[英]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.