Search code examples
typescriptreact-nativeflowtypetypecheckingflow-typed

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?


Solution

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

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