Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antd Select handle functions types typescript

I have a question. So Antd provides custom Select input and with it some functions like onSelect, onChange etc. I'm using onSelect and this is what this function passes as arguments:

(JSX attribute) onSelect?: ((value: string | number | LabeledValue, option: OptionData | 
OptionGroupData) => void) | undefined

So my handleSelect function gets 2 arguments, the first is the value of an option itself and the second one is the whole option tag with all data. I was able to figure out value type and import it from antd but for option I cannot find any suitable files to import it type from, so I'm getting an error because I can't set my second arg type properly

const handleSelect: (value: SelectValue, option: any) => void

And the option arg she be type:

option: OptionData | OptionGroupData) => void) | undefined

How am I suppose to set this type, where can I get it from?

like image 671
Konrad Avatar asked Oct 24 '25 17:10

Konrad


1 Answers

Don't know if implementations changed since this question was made, but we solved importing:

import { OptionData, OptionGroupData } from "rc-select/lib/interface"

And where needed the type

option: OptionData | OptionGroupData | undefined

like image 114
Fabíola Avatar answered Oct 26 '25 08:10

Fabíola



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!