Skip to content

export Props types for end users#22372

Closed
chuckhacker wants to merge 1 commit intofacebook:masterfrom
chuckhacker:master
Closed

export Props types for end users#22372
chuckhacker wants to merge 1 commit intofacebook:masterfrom
chuckhacker:master

Conversation

@chuckhacker
Copy link
Copy Markdown

@chuckhacker chuckhacker commented Nov 21, 2018

Related to #22100

When using Flow, it is handy to be able to inherit from Props type for components in user code because the typing can be stricter.

For example:

type SubmitButtonProps = $ReadOnly<{|
  ...TouchableHighlightProps,

  onPress: ?() => void,
  style?: ?ViewStyleProp,
  title: string,
|}>;

Test Plan:

  • npm run prettier
  • npm run flow-check-ios
  • npm run flow-check-android

Release Notes:

[GENERAL] [ENHANCEMENT] [Components/Touchable/TouchableBounce.js] - export Props Flow types
[GENERAL] [ENHANCEMENT] [Components/Touchable/TouchableHighlight.js] - export Props Flow types
[GENERAL] [ENHANCEMENT] [Components/Touchable/TouchableOpacity.js] - export Props Flow types

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 21, 2018
@pull-bot
Copy link
Copy Markdown

Warnings
⚠️

📋 Test Plan - This PR appears to be missing a Test Plan.

⚠️

📋 Release Notes - This PR appears to be missing Release Notes.

Generated by 🚫 dangerJS

@TheChuckster
Copy link
Copy Markdown

Warnings

Test Plan - This PR appears to be missing a Test Plan.

Release Notes - This PR appears to be missing Release Notes.

Generated by dangerJS

Resolved

@elicwhite
Copy link
Copy Markdown
Member

elicwhite commented Nov 25, 2018

Thanks for the PR! There is actually an easier way to do this that doesn't require changes to core. You can use Flow's React.ElementProps utility type:

const {TouchableBounce} = require('react-native');
type TouchableBounceProps = React.ElementProps<typeof TouchableBounce>

Since React.ElementProps gives this information, we aren't exporting the types for every Component (and will be removing the currently exported prop flow types on components in the future).

@elicwhite elicwhite closed this Nov 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants