我正在尝试将javascript代码转换为打字稿。我有一个曾经在js中正常工作的类
class Model {
constructor(input, alias) {
this.tableName = input;
this.alias = alias;
}
}
但是现在我得到两个错误,说Property 'tableName' does not exist on type 'Model'
和Property 'alias' does not exist on type 'Model'
这也是我的tsconfig设置:
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES6",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "Node",
"noImplicitAny": false,
"strict": false,
"outDir": "./dist"
},
"include": ["controllers", "models", "module","routes","./app.ts"],
"ts-node": {
"transpileOnly": true
}
}
我对打字稿有点陌生,对此了解不多。
任何帮助将不胜感激
你必须定义属性
class Model {
tableName:string;
alias:string;
constructor(input, alias) {
this.tableName = input;
this.alias = alias;
}
}