Typescript Vue Prop没有初始值设定项,并且未在构造函数中明确指定

Typescript Vue Prop没有初始值设定项,并且未在构造函数中明确指定,typescript,vue.js,visual-studio-code,tslint,Typescript,Vue.js,Visual Studio Code,Tslint,我在Vue类组件中使用道具。道具在构造函数中定义,没有值。这可以很好地编译和工作,但是自从最新的VS Code/TSLint更新以来,我得到了以下警告: 属性“tag”没有初始值设定项,并且在构造函数中没有明确指定 Vue类组件 export default class Browser extends Vue { @Prop({default: '', required:false}) tag: string created(){ console.log("the tag

我在Vue类组件中使用道具。道具在构造函数中定义,没有值。这可以很好地编译和工作,但是自从最新的VS Code/TSLint更新以来,我得到了以下警告:

属性“tag”没有初始值设定项,并且在构造函数中没有明确指定

Vue类组件

export default class Browser extends Vue {
  @Prop({default: '', required:false})
  tag: string

  created(){
     console.log("the tag prop is " + this.tag)
  }
}
如果我指定了它,我会得到Vue警告,您不应该在子组件中操纵道具

[Vue warn]:避免直接变异道具,因为每当父组件重新渲染时,该值将被覆盖

既然这似乎主要是一个起毛问题,有没有办法禁用它?还是我的代码确实错了?

更新2020/06/15 我当时给出的最初答案是断断续续的,而不是正确的答案。答案是正确的方法;在道具名称后面添加

原始答案 我也有同样的问题。我通过在tsconfig.json的编译器选项中添加
“strictPropertyInitialization”:false、
来修复它

{
    "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/**/*"
    ]
}

您不需要设置
strictPropertyInitialization:false
来解决此问题

根据Microsoft TypeScript Vue Starter repo中的说明:

属性是通过在实例变量前面加上 @vue属性装饰程序包中的Prop()装饰程序。因为 --strictPropertyInitialization选项处于启用状态,我们需要告诉TypeScript,Vue将通过在 这告诉TypeScript“嘿,放松,其他人会 为该属性指定一个值。“

您只需将
附加到道具名称:

@Prop({default: '', required:false})
  tag!: string

您使用的是哪个版本的Typescript?必须相信这是一个linting问题,因为您确实在decorator中提供了一个默认值。@没错,但该值是在运行时提供的,而不是在tslint看到此值时提供的。