react-component / react-component/select

A typescript user should be able to specify the types for the options

Open
#595 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
938
Forks
482
Avg merge
15h 8m
Merged PRs (30d)
2

Description

Expected behavior:

I should be able to specify the strict option types as follows:

export const exampleComponent= () => {
    type SelectValues = 'jack' | 'lucy' | 'disabled' | 'Yiminghe';
    return (
        <div style={{ width: '250px' }}>
            <VtxSelect<SelectValues> size="middle" onChange={action('on-change')} defaultValue="jack">
                <VtxOption<SelectValues> value="jack">Jack</VtxOption>
                <VtxOption<SelectValues> value="lucy">Lucy</VtxOption>
                <VtxOption<SelectValues> value="disabled" disabled>
                    Disabled
                </VtxOption>
                <VtxOption<SelectValues> value="Yiminghe">yiminghe</VtxOption>
            </VtxSelect>
        </div>
    );
};

Actual Behavior:

I get the error Expected 0 type arguments, but got 1.ts(2558)

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 TypeScript declarations for the VtxSelect and VtxOption components named in the example. Reproduce the Expected 0 type arguments error with the generic usage shown, then verify that the declared option value type is accepted and incompatible values are rejected by TypeScript.

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.