You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Svelte项目jsonfig.json中importsNotUsedAsValues弃用问题求助

Svelte项目tsconfig.json配置更新(解决弃用警告)

错误提示

选项'importsNotUsedAsValues'已被弃用,将在TypeScript 5.5版本停止生效。可指定编译器选项'"ignoreDeprecations": "5.0"'来屏蔽该错误,请改用'verbatimModuleSyntax'。

修改后的完整配置

{
  "compilerOptions": {
    "moduleResolution": "Node",
    "target": "ESNext",
    "module": "ESNext",
    /**
     * svelte-preprocess无法区分导入的是值还是类型,因此请告知TypeScript强制对类型使用`import type`而非`import`。
     */
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "resolveJsonModule": true,
    /**
     * 为使Svelte编译器的警告/错误显示在正确位置,默认启用源映射。
     */
    "sourceMap": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    /**
     * 默认对.svelte和.js文件中的JS进行类型检查。若需使用动态类型,请禁用此选项。
     */
    "checkJs": true
  },
  /**
   * 使用global.d.ts而非compilerOptions.types,以避免限制类型声明。
   */
  "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}

修改说明

  1. 移除已弃用的"importsNotUsedAsValues": "error"配置项
  2. 新增"verbatimModuleSyntax": true,该选项完全替代原配置的作用:强制要求类型导入必须使用import type语法,非类型导入不能附加type关键字,完美适配svelte-preprocess的限制需求。

临时兼容方案(不推荐)

如果暂时不想调整配置,可以添加"ignoreDeprecations": "5.0"到compilerOptions中屏蔽警告,但该方案只是临时手段,TypeScript 5.5版本后旧选项会彻底失效,建议尽早替换。

内容的提问来源于stack exchange,提问作者SSFJHGKJFHG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 18:47:46