问题描述
我目前正在将MysqL2 lib用于我的节点打字稿项目,但我似乎无法想到类型错误/不匹配。错误是
Type 'PoolConnection' is missing the following properties from type 'PoolConnection': promise,execute,ping
这是我在文件中设置的子集
import * as MysqL from 'MysqL2';
import { PoolConnection,PoolCluster } from 'MysqL2/promise';
let poolCluster: PoolCluster;
export const initPoolCluster = function (mode: Mode): void {
poolCluster = MysqL.createPoolCluster();
if (mode === Mode.PRODUCTION) {
// for multiple pools in the cluster
poolCluster.add('WRITE',poolWriteConfig);
poolCluster.add('READ1',poolRead1Config);
poolCluster.add('READ2',poolRead2Config);
} else {
// for a single pool in the cluster
poolCluster.add('*',poolConfig);
}
};
type MyPoolConnection = {
err: NodeJS.ErrnoException | null;
conn: PoolConnection | null;
};
export const get = async (type: Operation): Promise<MyPoolConnection> => {
return new Promise((resolve,reject) => {
poolCluster.getConnection(`${type}*`,(err,connection) => {
if (err) {
reject({ err: err,conn: null });
} else {
resolve({ err: null,conn: connection }); <-------
}
});
});
};
连接对象抛出了上面的错误/不匹配问题,我只是不确定在哪里寻找解决的方法。香港专业教育学院认为@ types / MysqL2不具有'MysqL.createPoolCluster();'的类型。所以它是从@ types / MysqL获取的,如何将其作为PoolConnection类型返回?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)