react-component / react-component/table

Use DataIndex<RecordType> for better constraints?

Open
#435 0 comments 1 reaction 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.