【发布时间】:2021-07-02 06:58:34
【问题描述】:
我正在尝试在我的打字稿类中使用装饰器。 这就是我正在尝试的
import {
Model,
ModelCtor
} from 'sequelize/types';
function decorator(constructor) {
//
}
@decorator
class Service implements IService {
// when using 'private User: any' instead it works fine
constructor(private User: ModelCtor < Model < any, any >> ) {
}
}
我收到以下错误:Error: Cannot find module 'sequelize/types'
在这个特定的示例中,我正在导入 sequelize/types,但它对任何其他 d.ts 文件的工作方式都相同。
我已经安装了类型并且在没有装饰器的情况下工作正常。此外,在为构造函数参数定义类型为any 时也不会抱怨:private User: any
我搜索了但没有找到有用的东西。
顺便说一下,我的 tsconfig.json 是:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./build",
"sourceMap": true,
"typeRoots": [
"./node_modules/@types",
"./lib/types/index",
"./node_modules/sequelize/types/"
],
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"pretty": true,
"allowJs": true,
"noEmit": false,
"esModuleInterop": true,
},
"include": [
"./index.ts",
"./lib"
],
"exclude": [
"node_modules",
"tests",
".vscode",
"doc",
]
}
【问题讨论】:
-
您好,您找到解决方案了吗?
标签: typescript typescript-decorator