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

如何解决PhpStorm/WebStorm识别TypeScript类型导入为错误的问题

解决PhpStorm/WebStorm对TypeScript类型导入报"', expected'"错误的问题

项目生产、开发环境运行正常,但IDE对以下类型导入语法持续报错提示"', expected'":

import {type UserConfig} from 'vite'
import { createPinia, type Pinia } from 'pinia';

解决方案:

  • 升级IDE的TypeScript版本支持
    这种type前缀的类型导入是TypeScript 4.5及以上版本才支持的语法。打开IDE设置(File > Settings > Languages & Frameworks > TypeScript),将TypeScript版本切换为项目本地安装的版本(需确保项目依赖的ts版本≥4.5),替代IDE内置的旧版本。

  • 修正tsconfig.json配置
    确保项目的tsconfig.json中compilerOptions配置支持ES模块语法:

    {
      "compilerOptions": {
        "module": "ESNext",
        "moduleResolution": "node16",
        "target": "ESNext",
        "strict": true
      }
    }
    

    保存配置后,IDE会自动重新识别语法。

  • 清除IDE缓存并重启
    执行File > Invalidate Caches...,勾选"Clear file system cache and local history",点击"Invalidate and Restart",清除可能导致识别异常的缓存。

  • 排查插件冲突
    禁用第三方TypeScript相关插件后重启IDE,排查是否是插件兼容性导致的语法识别错误。

内容的提问来源于stack exchange,提问作者Atlas-Pio

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 08:40:42