react-component / react-component/table
make `rowKey` more type safe
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.4k
- Forks
- 618
- Avg merge
- 10h 19m
- Merged PRs (30d)
- 2
Description
Describe the problem
From the source code, currently the type of rowKey attribute is string or callback function. However I think we can make the type of rowKey more precise.
What I suggest
Before
rowKey?: string | GetRowKey<RecordType>;
After
rowKey?: keyof RecordType | GetRowKey<RecordType>;
Because the rowKey attribute means that use dataSource[i][rowKey] as the key attribute that react wants.
This will make the type more precise. It will be nice that typescript can check if we have given the correct value to rowKey attribute.
Expected result
Before
const data = [{ id: 1, name: 'Tom' }, {id: 2, name: 'Bob' }];
return <Table dataSource={data} rowKey="username" />; // no error 😕
After
const data = [{ id: 1, name: 'Tom' }, {id: 2, name: 'Bob' }];
return <Table dataSource={data} rowKey="username" />; // TS ERROR!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/Table.tsx around line 119 and inspect the surrounding rowKey and GetRowKey type definitions. Verify the proposed typing against the dataSource examples, including rejecting a rowKey that is not a key of the record type, while preserving callback support.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100