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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generatedTypes/components/card/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export declare type CardProps = ViewProps & TouchableOpacityProps & {
/**
* action for when pressing the card
*/
onPress?: () => void;
onPress?: TouchableOpacityProps['onPress'];
/**
* whether the card should have shadow or not
*/
Expand Down Expand Up @@ -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

/**
* whether the card should have shadow or not
*/
Expand Down
4 changes: 2 additions & 2 deletions generatedTypes/components/modal/TopBar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ModalTopBarProps {
/**
* done action callback
*/
onDone?: (props: any) => void;
onDone?: (props?: any) => void;
/**
* cancel action props (Button props)
*/
Expand All @@ -42,7 +42,7 @@ export interface ModalTopBarProps {
/**
* cancel action callback
*/
onCancel?: (props: any) => void;
onCancel?: (props?: any) => void;
/**
* whether to include status bar or not (height claculations)
*/
Expand Down
2 changes: 1 addition & 1 deletion generatedTypes/components/touchableOpacity/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)

}
declare const _default: React.ComponentClass<TouchableOpacityProps & {
useCustomTheme?: boolean | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/components/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type CardProps = ViewProps &
/**
* action for when pressing the card
*/
onPress?: () => void;
onPress?: TouchableOpacityProps['onPress'];
/**
* whether the card should have shadow or not
*/
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ModalTopBarProps {
/**
* done action callback
*/
onDone?: (props: any) => void;
onDone?: (props?: any) => void;
/**
* cancel action props (Button props)
*/
Expand All @@ -48,7 +48,7 @@ export interface ModalTopBarProps {
/**
* cancel action callback
*/
onCancel?: (props: any) => void;
onCancel?: (props?: any) => void;
/**
* whether to include status bar or not (height claculations)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/components/touchableOpacity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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;
}

type Props = BaseComponentInjectedProps &
Expand Down