DouyinFE / semi-design

🚀A modern, comprehensive, flexible design system and React UI library. 🎨 Provide more than 3000+ Design Tokens, easy to build your design system. Make Semi Design to Any Design. 🧑🏻‍💻 Design to Code in one click

Home Page:https://semi.design

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Select] 支持传递value的类型

xmsz-stu opened this issue · comments

Which Component Need Enhancement 期望新增功能的组件

  • Select

What does the proposed API look like 期望支持的API

<Select<string>
   value?: string;
   onChange?: (value?: string) => void
 />

Feature Description 功能描述

因为如果不传递string类型,则value的值是'string | number | any[] | Record<string, any> | undefined
然后一般比如传递onChange的时候都是, (value?: string) => void ,现在就会遇到

 Type 'Dispatch<SetStateAction<string | undefined>>' is not assignable to type '(value: string | number | any[] | Record<string, any> | undefined) => void'.
  Types of parameters 'value' and 'value' are incompatible.
    Type 'string | number | any[] | Record<string, any> | undefined' is not assignable to type 'SetStateAction<string | undefined>'.
      Type 'number' is not assignable to type 'SetStateAction<string | undefined>'.

必须写成

<Select onChange={(v) => onChange(v as string)}/>

非常麻烦,每次都得写一个

Additional information 补充说明