从TypeScript 5.0开始,选项“importsNotUsedAsValues”和“preserveValueImports”已经被标记为Deprecated,并将在TypeScript5.5之后停止支持,请改用“verbatimModuleSyntax”选项替代。如果想继续使用5.x版本,增加一个选项:在tsconfig.json 中增加 "ignoreDeprecations": "5.0",报警就不再提示了,或者直接设置verbatimModuleSyntax为false,或者切换到4.X版本。搜索了一下,网上大都建议 "ignoreDeprecations": "5.0",但是我不想。
要点:
由于我的项目是全新使用uni-app+vue3+vite+typescript搭建,没有历史,我想使用TypeScript 5.x版本,所以上面的设置对我无效,同时对于新手来说,打开项目中的tsconfig.json文件时,根本看不到报错的两个选项“importsNotUsedAsValues”和“preserveValueImports”,它的配置文件是这样的:
{
"extends": "@vue/tsconfig/tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"lib": ["esnext", "dom"],
"types": ["@dcloudio/types"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}
明明看不到这两个选项的配置,但是却一直提示错误,这是因为tsconfig.json中使用了这个语句"extends": "@vue/tsconfig/tsconfig.json",它加载了指定的ts配置,找到这个文件,你会看到报错的两个选项,将它注释掉即可:
// For `<script setup>`
// See <https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#preserve-value-imports>
//"preserveValueImports": true,
// Enforce using `import type` instead of `import` for types
//"importsNotUsedAsValues": "error",
同时在根目录的tsconfig.json中添加verbatimModuleSyntax的配置:
{
"extends": "@vue/tsconfig/tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"lib": ["esnext", "dom"],
"types": ["@dcloudio/types"],
"verbatimModuleSyntax": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}



2157

被折叠的 条评论
为什么被折叠?



