我有一个为 extsting npm 包编写的声明文件,但似乎没有声明一种方法,我尝试声明它,但出现错误。请帮帮我。
现有 d.ts 文件的结构:
declare module "mongoose" {
...
class Document {}
interface Document extends MongooseDocument, NodeJS.EventEmitter, ModelProperties {
increment(): this;
remove(fn?: (err: any, product: this) => void): Promise<this>;
...
}
}
我尝试添加到接口文档方法deleteOne。我的定制.d.ts:
declare module "mongoose" {
interface Document {
deleteOne(fn?: (err: any, product: this) => void): Promise<this>;
}
}
但我仍然收到错误“类型上不存在属性‘deleteOne’”。
如果您需要,这是我的 tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"removeComments": true,
"esModuleInterop": true,
"moduleResolution": "node",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"pretty": true,
"resolveJsonModule": true,
"sourceMap": true,
"target": "ES2018",
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist",
"**/*.spec.ts"
]
}
我的 custom.d.ts 文件位于“src/”目录中。