JedWatson / JedWatson/react-select
Typescript Creatable `formatOptionLabel` not provide suitable option type to detect new create option
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
Problem

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:

New Option:

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