简体   繁体   中英

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

In my react-native application I have a TextInput component. The TextInput reads some types from the following path:

/Users/karl/Library/Caches/typescript/3.6/node_modules/@types/react-native/index.d.ts

This file has a bunch of types in including:

export type KeyboardType = 'default' | 'email-address' | 'numeric' | 'phone-pad';

I can access this file by cmd + clicking on a prop I have added, (using vscode) to go to it's definition.

What I am wondering though is how I can reference the types in this file, so I can use them in my Flow typing definitions?

I want to be able to do something like:

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

How I can go about this?

Actually, for flow-typed you should directly add the types from component source:

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

But for typescript first, install @types/react-native and then get all the types from react-native ;

import { ReturnKeyType, KeyboardType } from 'react-native';

You're doing everything right, except you don't need the word type after import :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM