React Native TypeScript 错误:模块“react-native”没有导出成员“外观”

jef*_*wis 12 typescript reactjs react-native

我最近在我的应用程序中实现了黑暗模式,但在使用以下命令构建 npm 包时遇到错误npm build. 该代码有效,但是有没有办法或理由来消除此错误?

React Native 文档:外观

错误

src/ContactActionSheet.tsx:3:10 - error TS2305: Module '"react-native"' has no exported member 'Appearance'.

3 import { Appearance, Dimensions, StyleSheet, Text, View, Linking, TouchableOpacity } from 'react-native';
Run Code Online (Sandbox Code Playgroud)

JSX

// Imports: Dependencies
import { Appearance, Dimensions, StyleSheet, Text, View, Linking, TouchableOpacity } from 'react-native';

// Dark Mode
const colorScheme = Appearance.getColorScheme();
Run Code Online (Sandbox Code Playgroud)

jef*_*wis 23

问题在于 npm 包@types/react-native需要更新。

  • `npm install --save @types/react-native` (6认同)