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

Visual Studio 2022 忽略tsconfig.json致IntelliSense报错求助

解决IntelliSense忽略tsconfig.json的问题

1. 修正tsconfig.json的include范围

当前你的include字段仅包含两个声明文件,src目录下的业务代码完全没被纳入TypeScript的检查范围,这是IntelliSense失效的核心原因之一。修改include字段:

"include": [
  "./declaration.d.ts",
  "./src/**/*" // 匹配src下所有文件及子目录
],

2. 补全paths配置依赖的baseUrl

paths别名配置必须配合baseUrl才能让TypeScript正确解析路径,在compilerOptions中添加:

"baseUrl": "./",

完整的路径配置部分如下:

"compilerOptions": {
  // ...其他原有配置
  "baseUrl": "./",
  "paths": {
    "@/*": [ "./src/*" ]
  }
}

3. 切换到项目本地的TypeScript版本

VS Code默认可能使用内置TS版本,和项目依赖版本不一致会导致配置兼容问题:

  • 打开任意TS/TSX文件,点击右下角显示的TS版本号
  • 在弹出选项中选择Use Workspace Version

4. 强制重启TypeScript Server

若以上步骤无效,彻底重启TS Server:

  • 按下Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac)
  • 输入TypeScript: Restart TS Server并执行

5. 验证React Hook Form的类型依赖

确保安装了官方类型定义包(即使已安装react-hook-form,类型包可能缺失):

npm install @types/react-hook-form --save-dev
# 或使用yarn
yarn add @types/react-hook-form -D

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 22:35:19