Skip to content

Touchables using forwardRef are not covered by Flow #28726

@draperunner

Description

@draperunner

Description

When importing TouchableOpacity, it is treated as any by Flow. Same goes for TouchableHighlight. I think this is because of the use of React.forwardRef in their respective files. Flow understands TouchableWithoutFeedback, which does not use forwardRef.

This blog post might be relevant for typing forwardRef in Flow: https://medium.com/flow-type/supporting-react-forwardref-and-beyond-f8dd88f35544

I was hoping to use React.ElementConfig<typeof TouchableOpacity> to type the Props of my own Button component, but that does not work because of this. I am using React.ElementConfig<typeof TouchableWithoutFeedback> now as a workaround.

React Native version:

0.62.2
Flow version 0.113.0

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Import TouchableOpacity in a component file
  2. Use your Flow tools in your editor to inspect that TouchableOpacity is treated as any or use it "illegally" and run flow to see that it passes. Like for instance
cons x: number  = TouchableOpacity

Expected Results

I expect Flow to understand that TouchableOpacity is not "any", but a React component with a set of valid Props.

Snack, code example, screenshot, or link to a repository:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions