程序本身运行良好,但 Typescript 在我的组件返回函数中用红色强调了很多项目。特别是我进口的任何东西react-native
。
诸如此类的任何东西View
都会Button
抛出这些“错误”。我在引号中说错误是因为应用程序运行没有任何问题。我的 IDE(VS 代码)中的打字稿是唯一抱怨的事情。如果我选择(通过右下角的状态栏选择器)JavaScript React 或 TypeScript React,它会抛出这些错误。这是一个例子:
这是我的 package.json 的重要部分
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-navigation/native": "^5.7.6",
"@eact-navigation/stack": "^5.9.3",
"expo": "~39.0.2",
"expo-status-bar": "~1.0.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz",
"react-native-screens": "~2.10.1",
"react-native-web": "~0.13.12",
"react-native-gesture-handler": "~1.7.0",
"react-native-reanimated": "~1.13.0",
"react-native-safe-area-context": "3.1.4",
"@react-native-community/masked-view": "0.1.10"
},
"devDependencies": {
"react-native-web": "~0.13.7",
"@types/react": "*",
"@types/react-dom": "*",
"@types/react-native": "*",
"typescript": "~3.9.5"
},
这是抛出这些错误的文件的样子:
import { StatusBar } from "expo-status-bar";
import React, { useState } from "react";
import { StyleSheet, Text, View, TextInput, Button } from "react-native";
const SummaryScreen = ({ navigation }) => {
const accountDetailsPage = () => {
navigation.navigate("Account Details");
};
const contactDetailsPage = () => {
navigation.navigate("Contact Details");
};
return (
<View style={styles.container}>
<Text>HERE IS A BUNCH OF TEXT</Text>
<Button title="Account Details" onPress={accountDetailsPage} />
<Button title="Contact Details" onPress={contactDetailsPage} />
</View>
);
};
我认为重要的是要注意我不会在@react-navigation诸如<Navigator>和之类创建的组件上遇到这些错误<Stack.Screen ...
有点相关,VS Code 中的某些东西抱怨它找不到模块,useState但在运行时也能正常工作,没有错误
弑天下
相关分类