升级依赖后Eslint 9+TypeScript+Vue中defineEmits解析错误排查
Astro博客依赖升级后ESLint+TypeScript+Vue解析错误问题
升级Astro博客依赖后,碰到了最新版ESLint搭配TypeScript+Vue的诡异问题。已经严格按照ESLint、typescript-eslint、eslint-plugin-vue以及eslint-config-prettier的官方文档完成配置,但异常依旧,找不到问题根源。
ESLint对以下代码块抛出Parsing error: Unexpected token错误,但这段写法完全符合Vue官方文档中关于defineEmits的类型定义规范:
<script setup lang="ts"> const emit = defineEmits<{ (e: 'change', id: number): void (e: 'update', value: string): void }>() </script>
我已准备好该错误的最小复现示例仓库,目前看起来Vue的配置并未被正确加载,请问我到底遗漏了什么配置?
项目package.json配置
{ "name": "typescript-eslint-vue", "version": "0.0.0", "private": true, "type": "module", "scripts": { "check": "vue-tsc --noEmit && tsc --noEmit ", "lint": "eslint --fix src" }, "devDependencies": { "@eslint/js": "^9.13.0", "@types/eslint__js": "^8.42.3", "@typescript-eslint/parser": "^8.11.0", "eslint": "^9.13.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-vue": "^9.10.0", "prettier": "^3.3.3", "typescript": "^5.6.3", "typescript-eslint": "^8.11.0", "vue": "^3.5.12", "vue-tsc": "^2.1.6" }, "dependencies": { "@vue/tsconfig": "^0.5.1", "@vueuse/core": "^11.1.0" } }
ESLint配置文件
import eslint from "@eslint/js"; import prettierConfig from "eslint-config-prettier"; import pluginVue from "eslint-plugin-vue"; import tseslint from "typescript-eslint"; export default tseslint.config( eslint.configs.recommended, ...tseslint.configs.recommended, ...pluginVue.configs["flat/recommended"], prettierConfig, { files: ["**/*.ts", "**/*.vue"], rules: {}, } );
内容的提问来源于stack exchange,提问作者Theiaz
相关产品推荐
相关产品推荐

