3

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?

1
  • Actually I've same issue and leave an answer for flow-typed and typescript both. I leave an upvote to your awesome post. Commented Aug 15, 2020 at 6:33

2 Answers 2

4

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 type { ReturnKeyType, KeyboardType } from 'react-native';
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

2 Comments

Wow. It really is Monday. Thank you 🎉
I actually now get this Flow(InferError). But it's typed absolutely fine. Any ideas? Cannot import 'KeyboardType' because there is no 'KeyboardType' export in 'react-native'. Flow(InferError)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.