Skip to content
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

[TypeScript] Fix onSuccess / onFailure types #5853

Merged
merged 2 commits into from
Feb 4, 2021
Merged

Conversation

fzaninotto
Copy link
Member

Closes #5761
Supersedes #5787

@fzaninotto fzaninotto added the RFR Ready For Review label Feb 2, 2021
@fzaninotto fzaninotto added this to the 3.12.1 milestone Feb 2, 2021
Comment on lines +289 to +290
export type OnSuccess = (response?: any) => void;
export type OnFailure = (error?: 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.

We should probably avoid any in favor of unknow. See #5834

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand the benefits and shortcomings of any vs unknown. What I've read at https://stackoverflow.com/questions/51439843/unknown-vs-any tells me that there may be drawbacks for end users (like the obligation to perform type checking on an unknown value before using it).

Let's keep the two discussions separate.

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

There is an eslint warning ;)

@HendrikRoehm
Copy link

Additionally, the main fix for #5761 is missing:
OnSuccess should be typed as ({ data } : { data: Record}) => void

@djhi
Copy link
Contributor

djhi commented Feb 3, 2021

@HendrikRoehm:

Additionally, the main fix for #5761 is missing:

No, data is not always a Record. It could be an array of Record for useGetList or anything in the case of custom dataProvider functions

@HendrikRoehm
Copy link

HendrikRoehm commented Feb 3, 2021

@djhi I guess the main problem here is that there exists at least 3 different kind of onSuccess properties, which expect different types, but are all using the same OnSuccess type. Plz check my issue: In the onCreateController, it need to be of the type I have mentioned above. So at least the type there should be changed.

@fzaninotto
Copy link
Member Author

@HendrikRoehm You said:

In the onCreateController, it need to be of the type I have mentioned above

What do you mean? Do you have a compilation error? If so, with which code?

Also, it's only in dataProvider.create() that the onsuccess callback can expect a defined response with a data key.

@djhi djhi merged commit c61e7a1 into master Feb 4, 2021
@djhi djhi deleted the Fix-onSuccess-types branch February 4, 2021 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create prop onSuccess has wrong typing
3 participants