我有一个针对现有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>;
...
}
}
我尝试添加到接口Document的deleteOne方法。我的custom.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/'目录中。
@types/mongoose
?https://www.npmjs.com/package/@types/mongoose - paperballdocument
接口没有继承interface Document extends MongooseDocument, NodeJS.EventEmitter, ModelProperties
。 - hazardous