React Native - IntelliSense建议react-native/types而不是react-native

klsxnrf1  于 2023-04-07  发布在  React
关注(0)|答案(1)|浏览(198)

我想从react-native导入<View,但得到的却是react-native/types

我如何解决这个问题?这是一个从头开始的新项目,我像文档指南一样添加了TypeScript:
yarn add --dev @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript

b0zn9rqh

b0zn9rqh1#

我也有这个问题,但我设法解决它 * 以某种方式 *. x1c 0d1x

简短回答

检查你是否安装了@types/react@types/react-native作为开发依赖。这是我认为对我有效的步骤。

详细回答

我不知道是什么解决了这个问题,所以这是我所做的所有步骤:
1.我检查了我的eslint设置:

{
  "extends": ["react-native-wcandillon", "plugin:prettier/recommended"],
  "plugins": ["prettier"],
  "rules": {
    "max-len": ["error", { "code": 120 }],
    "prettier/prettier": [
      "warn",
      {
        "singleQuote": false,
        "printWidth": 120
      }
    ]
  }
}

1.我检查了我的babel设置

module.exports = {
  presets: ["module:metro-react-native-babel-preset"],
  plugins: ["react-native-reanimated/plugin"],
};

1.我检查了我的tsconfig设置:

{
  "extends": "eslint-config-react-native-wcandillon/tsconfig.base",
}

1.我检查了我的--dev依赖项并安装了一些(也许这有帮助?)

"devDependencies": {
    "@babel/core": "^7.21.3",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.21.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.3",
    "@types/react": "^18.0.29",
    "@types/react-native": "^0.71.5",
    "@types/react-test-renderer": "^18.0.0",
    "@types/uuid": "^9.0.1",
    "@typescript-eslint/eslint-plugin": "^5.56.0",
    "@typescript-eslint/parser": "^5.56.0",
    "eslint": "^8.36.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-config-react-native-wcandillon": "^3.9.1",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-react": "^7.32.2",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.0",
    "prettier": "2.8.7",
    "react-native-svg-transformer": "^1.0.0",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },

相关问题