react-component / react-component/table
Use DataIndex<RecordType> for better constraints?
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.4k
- Forks
- 618
- Avg merge
- 10h 19m
- Merged PRs (30d)
- 2
Description
I'd like to propose this change:
Before:
export declare type DataIndex = string | number | (string | number)[];
After:
export declare type DataIndex<RecordType> = keyof RecordType | number | (keyof RecordType | number)[];
That way, you get full type checking on dataIndex like here:
const columns : ColumnsType<Client>= [
{
title: 'Name',
dataIndex: 'name', // If 'name' does not exist for type Client, a Typescript error will occur
key: 'name',
render: text => <a>{text}</a>
},
]
If you like it, I can send a PR.
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 by locating the DataIndex and ColumnsType type declarations and inspect how dataIndex is used throughout the table types. Compare the proposed generic constraint with existing usages, then verify that valid keys type-check and invalid keys produce TypeScript errors without breaking numeric or array indexes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100