被引用的意外标记是!
,即非空断言运算符。我怎样才能仍然使用 Non-null 断言运算符并摆脱此错误?
46:43 error Parsing error: Unexpected token
16 | export default class MyComponent extends Vue {
> 18 | @Prop({ default: 'Default Title' }) title!: string
.eslintrc.js:
module.exports = {
root: true,
env: {
browser: true,
node: true
},
parserOptions: {
parser: 'babel-eslint',
ecmaFeatures: {
legacyDecorators: true
}
},
extends: [
'@nuxtjs',
'plugin:nuxt/recommended'
],
rules: {
"quotemark": 0,
"whitespace": [0, "check-branch", "check-operator", "check-typecast", "check-preblock", "check-postbrace", "check-type"],
"interface-name": 0,
"ordered-imports": 0,
"object-literal-sort-keys": 0,
"no-consecutive-blank-lines": 0,
"semicolon": 0,
"vue/html-self-closing": ["error", {
"html": {
"void": "any",
"normal": "any",
"component": "always"
},
"svg": "never",
"math": "never"
}],
"trailing-comma": 0,
"no-console": 0,
"no-string-literal": 0,
"no-var-requires": 0,
"ban-types": 0,
}
}
这可能只是一个错误或babel-eslint
的错误配置,但是如果你使用带有eslint
的Typescript,你可能会最好使用@typescript-eslint/parser
- 这是一个旨在处理TS代码的解析器。
使用该解析器,您还可以使用具有一些特定于lintingTypescript代码的eslint规则以及基本lint规则的一些更新版本的@typescript-eslint/plugin
,以更好地处理Typescript代码。
您可以查看@typescript-eslint
monorepo 的自述文件;有关将 ESLint 与 Typescript 一起使用的更多信息。