大家好,我正在将我的 vue3 项目从 js 迁移到 typescript,我遇到了这个问题:
这是我在 .vue 文件中的代码
<script setup lang="ts">
const toto = (msg: string) => {
console.log(msg)
}
</script>
这是我的 eslintrc.js
module.exports = {
'env': {
'browser': true,
'es2021': true
},
'extends': [
'eslint:recommended',
'plugin:vue/vue3-essential'
],
'parserOptions': {
'ecmaVersion': 13,
'sourceType': 'module'
},
'plugins': [
'vue'
],
'rules': {
'vue/multi-word-component-names': 'off',
'vue/object-curly-spacing': [2, 'always'],
'vue/html-closing-bracket-spacing': [2, {
'selfClosingTag': 'always'
}],
'vue/max-attributes-per-line': [2, {
'singleline': {
'max': 1
},
'multiline': {
'max': 1
}
}],
'semi': [2, 'never']
}
}
有人可以帮助我吗?谢谢🙏
最佳答案
您需要配置 eslint 以支持 typescript,因为 eslint 不支持开箱即用。 首先,你需要安装 @typescript-eslint/parser然后 @typescript-eslint/eslint-plugin . 一旦你安装了这些,只需更新你的配置如下-
module.exports = {
'env': {
'browser': true,
'es2021': true,
node: true
},
'extends': [
'eslint:recommended',
'plugin:vue/vue3-essential'
],
'parserOptions': {
'ecmaVersion': 12,
'sourceType': 'module',
parser: '@typescript-eslint/parser'
},
'plugins': [
'vue',
'@typescript-eslint'
],
'rules': {
'vue/multi-word-component-names': 'off',
'vue/object-curly-spacing': [2, 'always'],
'vue/html-closing-bracket-spacing': [2, {
'selfClosingTag': 'always'
}],
'vue/max-attributes-per-line': [2, {
'singleline': {
'max': 1
},
'multiline': {
'max': 1
}
}],
'semi': [2, 'never']
}
}
关于typescript - ESLint:解析错误:意外的 token :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70083042/