エラー:error Type string trivially inferred from a string literal, remove type annotation @typescript-eslint/no-inferrable-types
エラー内容
error Type string trivially inferred from a string literal, remove type annotation @typescript-eslint/no-inferrable-types
エラーが出たコード
import { Component, Prop, Vue } from 'vue-property-decorator'; @Component({}) export default class MyComponent extends Vue{ @Prop() private firstProperty: string = '最初のプロパティ'; private secondProperty: string = '二番目のプロパティ'; }
エラーを消せたコード
import { Component, Prop, Vue } from 'vue-property-decorator'; @Component({}) export default class MyComponent extends Vue{ @Prop() private firstProperty = '最初のプロパティ'; private secondProperty = '二番目のプロパティ'; }
こちらでエラーについて説明をみた。 【VSCodeのエラー】Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types) | おっくソぶろぐ
要は型推論できるような変数宣言初期化は型を敢えて書かなくて良いってこと。
このlintを消したかっったらこちらを参照すると良い。 今実行しているnode をctrl cで止めて再実行(serve でもbuild)すると同じエラーは出なくなる。
If you came here looking for an eslint solution because tslint is being deprecated, add this rule to your .eslintrc.js file: module.exports = { ...m rules: { ..., "@typescript-eslint/no-inferrable-types": "off", ... }, };