Warm tip: This article is reproduced from serverfault.com, please click

Property 'tableName' does not exist on type 'Model'

发布于 2020-11-28 10:41:27

I'm trying to convert a javascript code to typescript. I have a class which used to work properly in js

class Model {

    constructor(input, alias) {
        this.tableName = input;
        this.alias = alias;
    }
}

but now I get two errors saying Property 'tableName' does not exist on type 'Model' and Property 'alias' does not exist on type 'Model'

also this is my tsconfig settings :

{
    "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
    }
  }

I'm kinda new to typescript and don't know much about it.

any help will be appreciated

Questioner
amiryeg1
Viewed
0
farvilain 2020-11-28 18:43:48

You must define the property

class Model {
    tableName:string;
    alias:string;
    constructor(input, alias) {
        this.tableName = input;
        this.alias = alias;
    }
}

https://www.typescriptlang.org/docs/handbook/classes.html