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

Expo+React Native TS项目:IntelliSense提示react-native/types而非react-native的解决方法

解决VS Code IntelliSense自动提示导入react-native/types的问题

1. 调整tsconfig.json配置

在compilerOptions中添加types字段,明确指定优先使用react-native的类型,覆盖默认的类型查找逻辑:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true,
    "jsx": "react",
    "types": ["react-native"]
  },
  "exclude": ["node_modules"]
}

2. 移除冗余的@types/react-native依赖

Expo 48+搭配React Native 0.71.x时,React Native本身已经内置了类型定义,额外安装@types/react-native会导致类型冲突,执行命令卸载:

npm uninstall @types/react-native --save-dev
# 若使用yarn则执行
yarn remove @types/react-native --dev

3. 重启VS Code的TypeScript服务

打开VS Code命令面板(Ctrl+Shift+P / Cmd+Shift+P),输入TypeScript: Restart TS Server,重启后让配置生效。

4. 确认VS Code使用项目本地的TypeScript版本

点击VS Code右下角的TypeScript版本提示,选择"Use Workspace Version",确保使用项目安装的typescript@4.9.4而非全局版本,避免版本不兼容引发的提示异常。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 19:02:06