簡體   English   中英

如何通過 Typescript 為 Flow 導入 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM