Skip to content

Fix callback props typings in various components #1250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2021

Conversation

ethanshar
Copy link
Collaborator

Description

Fix callback props typings in components like: TouchableOpacity, Card and Modal.TopBar

Changelog

Fix callback props typings in components like: TouchableOpacity, Card and Modal.TopBar

@@ -30,7 +30,7 @@ export interface TouchableOpacityProps extends Omit<RNTouchableOpacityProps, 'st
*/
customValue?: any;
style?: StyleProp<ViewStyle> | Animated.AnimatedProps<StyleProp<ViewStyle>>;
onPress?: (props: TouchableOpacityProps | any) => void;
onPress?: (props?: TouchableOpacityProps | any) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the reason we need | any here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good point.
It was here before, but it might be irrelevant..
ill try to remove it and see if it affect us

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, there was a reason for the any type.
In TouchableOpacity we allow to pass a prop called customValue which can be anything you want to pass and get back in the onPress callback.
Because customValue can be anything, we have to support any type in the onPress callback, cause we can't tell what it'll be

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see now. make sense :)

@@ -83,7 +83,7 @@ declare const _default: React.ComponentClass<ViewProps & TouchableOpacityProps &
/**
* action for when pressing the card
*/
onPress?: (() => void) | undefined;
onPress?: ((props?: any) => void) | undefined;
Copy link
Contributor

@mendyEdri mendyEdri Apr 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is typescript still make us use | undefined although onPress is an optional?
(We don't use it in onCancel and onDone for example)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are looking at the generatedTypes file, this is how it generates the d.ts files apparently.
The source code doesn't have it

@ethanshar ethanshar requested a review from mendyEdri April 4, 2021 09:56
@mendyEdri mendyEdri merged commit 70e2978 into master Apr 4, 2021
@ethanshar ethanshar deleted the fix/callbackTypings branch July 26, 2021 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants