Vue Prop has no initializer and is not definitely assigned in the constructor

前端 未结 2 1351
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 23:27

I am using props in Vue Class components. The props are defined in the constructor without a value. This compiles and works fine, but since the latest VS Code / TSLint upda

2条回答
  •  失恋的感觉
    2020-12-17 23:37

    Update 2020/06/15

    My original answer I gave at the time was a intermittent solution and not the correct one. This answer is the correct way of doing this; Appending the prop name with a !.

    Original Answer

    I had the same issue. I fixed it by adding "strictPropertyInitialization": false, to tsconfig.json's compilerOptions.

    {
        "compilerOptions": {
            "outDir": "./built/",
            "sourceMap": true,
            "strict": true,
            "noImplicitReturns": true,
            "experimentalDecorators": true,
            "module": "es2015",
            "moduleResolution": "node",
            "target": "es5",
            "strictPropertyInitialization": false,
            "lib": [
                "es5",
                "es2015",
                "dom",
                "ScriptHost"
            ]
        },
        "include": [
            "./src/**/*"
        ]
    }
    

提交回复
热议问题