JedWatson / JedWatson/react-select

Typescript Creatable `formatOptionLabel` not provide suitable option type to detect new create option

Open
#5,064 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Problem

image

When i read the option data provided in formatOptionLabel, it give me the data type i using for options, which is Tag

export interface Tag{
    id: string;
    name: LocaleString;
    subject: Subject;
    createAt?: Nullable<DateTime>;
}

But when it is formatting a new label, it still give me the same type Tag, which i cannot extract the __isNew__, label, value property to generate New Option. Although i can do it with type any, which defeat purpose of typescript

option:
image

New Option:
image

It should be wrapped a type to provide original properties like filterOption did FilterOptionOption<Option>

Suggestion

This is my little 2 cents, use Tag as example

export interface FormatOptionLabeOptionl<Option> {
    readonly label: string;
    readonly value: string;
    readonly isNew: boolean;
    readonly data: Option;
}
(property) formatOptionLabel?: ((option: FormatOptionLabeOptionl<Tag>, formatOptionLabelMeta: FormatOptionLabelMeta<Tag>) => React.ReactNode) | undefined

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 at the TypeScript declaration for formatOptionLabel and compare its option parameter with FilterOptionOption; review related type tests if present. Done means the callback exposes the new-option properties without using any while preserving the user's original option type.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.