如何通过Typescript为Flow导入React本机类型?
在react原生应用程序中,我有一个如何通过Typescript为Flow导入React本机类型?,typescript,react-native,flowtype,typechecking,flow-typed,Typescript,React Native,Flowtype,Typechecking,Flow Typed,在react原生应用程序中,我有一个TextInput组件。TextInput从以下路径读取某些类型: /Users/karl/Library/Caches/typescript/3.6/node_modules/@types/react-native/index.d.ts 此文件中有一系列类型,包括: export type KeyboardType = 'default' | 'email-address' | 'numeric' | 'phone-pad'; 我可以通过cmd+单击我添
TextInput
组件。TextInput
从以下路径读取某些类型:
/Users/karl/Library/Caches/typescript/3.6/node_modules/@types/react-native/index.d.ts
此文件中有一系列类型,包括:
export type KeyboardType = 'default' | 'email-address' | 'numeric' | 'phone-pad';
我可以通过cmd+单击我添加的道具上的(使用vscode)来访问该文件,以转到其定义
但我想知道的是,如何引用此文件中的类型,以便在流类型定义中使用它们
我希望能够做到以下几点:
//伪代码
从“react native”导入类型{KeyboardType}
我该怎么做呢?你做的一切都很好,只是你不需要在导入后键入这个词:
import { Image, StyleSheet, ReturnKeyType, KeyboardType } from "react-native";
实际上,对于flow-typed
,您应该直接从组件源添加类型:
导入类型{
键盘式,
返回键类型,
}来自“react native/Libraries/Components/TextInput/TextInput”;
但是对于typescript
首先,安装@types/react native
,然后从react native
获取所有类型
从'react native'导入{ReturnKeyType,KeyboardType};
Wow。今天真的是星期一。谢谢,我现在真的得到了这个流(推断错误)
。但是打字绝对不错。有什么想法吗<代码>无法导入“KeyboardType”,因为“react native”中没有“KeyboardType”导出。Flow(InferError)
希望您了解语义差异。如果没有,研究它们实际上我有相同的问题,并为flow-typed
和typescript
两者都留下答案。我对你的精彩帖子投了一票。