JedWatson / JedWatson/react-select

Typescript for OptionType is not accepting React component

Open
#5,031 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

awaiting-author-response issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

The code will work as expected, but typescript ruqires me to have labels as strings.

Type '{ value: string; label: Element; }[]' is not assignable to type 'readonly ({ value: string; label: string; } | GroupBase<{ value: string; label: string; }>)[]'.ts(2322)
Select.d.ts(180, 5): The expected type comes from property 'options' which is declared here on type 'IntrinsicAttributes & Omit<Pick<Props<{ value: string; label: string; }, false, GroupBase<{ value: string; label: string; }>>, "value" | "form" | ... 28 more ... | "theme"> & Partial<...> & Partial<...>, StateManagedPropKeys> & Partial<...> & StateManagerAdditionalProps<...> & RefAttributes<...>'
 var options = [ {value: 0, label: () => (<span>{"All"}</span>)}],

     <Select
            ...
                    options={options}
           ...
                  />

You may also find the online Babel tool quite helpful if you wish to use ES6/ES7 syntax not yet supported by the browser you are using.

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 with the Select.d.ts declaration identified in the TypeScript error and reproduce the issue using the options example with a React element as label. The work is done when valid React component labels are accepted by the options type without the reported type error.

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.