JedWatson / JedWatson/react-select

Typescript: Return selectProps.value correct type based on IsMulti type instead of union type

Open
#5,152 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Hi everyone,

I've noticed that there is a union type for a value field instead of a single type for value field based on IsMulti generic type:

export type PropsValue<Option> = MultiValue<Option> | SingleValue<Option>;

I think we should use something like this:

export declare type PropsValue<Option, IsMulti extends boolean> = IsMulti extends true ? MultiValue<Option> : SingleValue<Option>;

to return the correct value type based on IsMulti generic type.

If you agree I can work on that fix.

Contributor guide

Open the contributing guide

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 tracing the PropsValue and IsMulti type declarations in the TypeScript sources and locating how selectProps.value uses them. Confirm the intended inference for single- and multi-select cases, then verify that the resulting value type is no longer an unconditional union with the relevant type checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.