-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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] Improve List exporter type #9968
Conversation
@@ -13,7 +18,8 @@ import { RaRecord, Identifier, DataProvider } from '../types'; | |||
* ); | |||
*/ | |||
const fetchRelatedRecords = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good time to make it a named export?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return jsonExport(commentsWithPostTitle, { | ||
headers: ['id', 'post_id', 'post_title', 'body'], | ||
}, (err, csv) => { | ||
downloadCSV(csv, 'comments'); | ||
}); | ||
}; | ||
|
||
const CommentList = () => ( | ||
<List exporter={exporter}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably go one step further and make exporter
typed when passing a type to List
:
<List<Comment> exporter={exporter}>
packages/ra-core/src/types.ts
Outdated
@@ -368,15 +368,17 @@ export interface ResourceProps { | |||
|
|||
export type Exporter = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporter should accept a generic type parameter for data
Problem
Writing a custom
<List exporter>
by hand is cumbersome, as TypeScript complains a lot.Solution
Avoid
any
in the type definition of thefetchRelatedRecords
function parameter.Give an example in the documentation.