Skip to content

Typings of SelectList lead to unnecessary type casts #371

Open
@shiba-codes

Description

@shiba-codes
  • @freenow/wave version: 1.30.0

Relevant code

      <SelectList
        onChange={(option) => {
          console.log(option.value); // "value" does not exist on type unknown
        }}
        options={[1, 2, 3].map((item) => ({ label: item, value: item }))} 
      />

What was expected to happen?

Current behavior is to type options as unknown[], and option arg in onChange callback as unknown.
It leads to unnecessary casting. Moreover, the shape of option is actually expected to be { label: string, value: string }, the component won't work otherwise.

I would expect the option's type to extend { label: string, value: string } and to be inferred from the list of provided options

Reproduction

https://codesandbox.io/s/wave-playground-4537vt?file=/src/App.tsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions