为什么打字稿要投入键入错误:属性' customSelect'在类型上不存在,任何nock<
我收到错误:
typing error: Property 'customSelect' does not exist on type 'Knex<any, unknown[]>'
从函数:
console.log({ inCreateConnection: ins.customSelect })
我在 typing.d.ts
中添加此接口以支持 customSelect
,就像 knex 文档:
// typings.d.ts
// from: https://knexjs.org/#typescript-support
// Extending Query Builder
import { Knex as KnexOriginal } from 'knex';
declare module 'knex' {
namespace Knex {
interface QueryBuilder {
customSelect<TRecord, TResult>(
value: number
): KnexOriginal.QueryBuilder<TRecord, TResult>;
}
}
}
打字在两个文件中都不起作用: https://github.com/wizardnet972/nx-knex/blob/main/libs/my-knex/src/lib/my-knex.ts#L10 和 https://github.com/wizardnet972/nx-knex/blob/main/libs/product-api/src/lib/product-api.ts#L6
import knex from 'knex';
export const createConnection = () => {
const ins = knex({
connection: {
host: 'localhost',
},
});
console.log({ inCreateConnection: ins.customSelect }) /// <--- typing error: Property 'customSelect' does not exist on type 'Knex<any, unknown[]>'
return ins;
};
这个问题是关于打字的,而不是应该运行。但打字应该可以工作。
为什么打字稿无法识别该功能?
I got an error:
typing error: Property 'customSelect' does not exist on type 'Knex<any, unknown[]>'
console.log({ inCreateConnection: ins.customSelect })
I add this interface in typing.d.ts
to support customSelect
just as say in knex docs:
// typings.d.ts
// from: https://knexjs.org/#typescript-support
// Extending Query Builder
import { Knex as KnexOriginal } from 'knex';
declare module 'knex' {
namespace Knex {
interface QueryBuilder {
customSelect<TRecord, TResult>(
value: number
): KnexOriginal.QueryBuilder<TRecord, TResult>;
}
}
}
The typings isn't work in both files:
https://github.com/wizardnet972/nx-knex/blob/main/libs/my-knex/src/lib/my-knex.ts#L10 and https://github.com/wizardnet972/nx-knex/blob/main/libs/product-api/src/lib/product-api.ts#L6
import knex from 'knex';
export const createConnection = () => {
const ins = knex({
connection: {
host: 'localhost',
},
});
console.log({ inCreateConnection: ins.customSelect }) /// <--- typing error: Property 'customSelect' does not exist on type 'Knex<any, unknown[]>'
return ins;
};
This problem is about typing and it's not supposed to run. but the typings are supposed to work.
Why typescript doesn't recognize the function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论