如何通过 Typescript for Flow 导入 React-Native 类型?

How to import React-Native types via Typescript for Flow?

在我的本机反应应用程序中,我有一个 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)转到它的定义。

不过我想知道的是如何引用此文件中的类型,以便在我的 Flow 类型定义中使用它们?

我希望能够做类似的事情:

// pseudocode
import type { KeyboardType } from 'react-native'

我该怎么做?

你做的一切都正确,除了你不需要 import 之后的词 type:

import { Image, StyleSheet, ReturnKeyType, KeyboardType } from "react-native";

实际上,对于 flow-typed 你应该直接从组件源添加类型:

import type {
  KeyboardType,
  ReturnKeyType,
} from 'react-native/Libraries/Components/TextInput/TextInput';

但对于 typescript,首先安装 @types/react-native,然后从 react-native;

获取所有类型
import type { ReturnKeyType, KeyboardType } from 'react-native';