[英]How to use an Intrinsic attributes as types in TypeScript react-native
[英]How to import React-Native types via Typescript for Flow?
在我的 react-native 应用程序中,我有一个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 + clicking
我添加的道具(使用 vscode)到 go 来访问这个文件。
我想知道的是如何引用此文件中的类型,以便可以在我的流类型定义中使用它们?
我希望能够做类似的事情:
// pseudocode
import type { KeyboardType } from 'react-native'
我怎么能 go 关于这个?
实际上,对于flow-typed
,您应该直接从组件源添加类型:
import type {
KeyboardType,
ReturnKeyType,
} from 'react-native/Libraries/Components/TextInput/TextInput';
但是对于typescript
首先,安装@types/react-native
然后从react-native
获取所有类型;
import { ReturnKeyType, KeyboardType } from 'react-native';
你做的一切都是对的,除了import
之后你不需要单词type
:
import { Image, StyleSheet, ReturnKeyType, KeyboardType } from "react-native";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.