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

React Native:IntelliSense提示react-native/types而非react-native的问题

解决IntelliSense提示从react-native/types导入View的问题
  • 修正tsconfig.json配置
    确保你的tsconfig.json正确继承官方配置并包含必要的类型声明:

    {
      "extends": "@tsconfig/react-native/tsconfig.json",
      "compilerOptions": {
        "types": ["react-native", "jest"]
      },
      "include": ["**/*.ts", "**/*.tsx"],
      "exclude": ["node_modules"]
    }
    
  • 清除TypeScript缓存并重启服务
    执行命令清除TS缓存:

    npx tsc --clearCache
    

    然后重启编辑器的TypeScript服务(以VS Code为例:按Ctrl+Shift+P,选择「TypeScript: Restart TS Server」)。

  • 确认编辑器使用工作区TypeScript版本
    在VS Code中按Ctrl+Shift+P,选择「TypeScript: Select TypeScript Version」,勾选「Use Workspace Version」,确保使用项目本地安装的typescript而非全局版本。

  • 检查React Native内置类型
    确认node_modules/react-native目录下存在index.d.ts文件(新版本React Native已内置TypeScript类型,无需额外安装@types/react-native)。如果不存在,尝试重新安装依赖:

    yarn install
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 01:45:44