Код: Выделить всё
type TRadio = {
type: 'RADIO'
value: string
}
type TChecks = {
type: 'CHECK'
value: string[]
}
type TGroup = TRadio | TChecks
const testFunc = ({ type, value }: TGroup) => {
if (type === 'CHECK') value // string[] 👍
if (type === 'RADIO') value // string 👍
}
const testFunc2 = ({ type = 'RADIO', value }: TGroup) => {
if (type === 'CHECK') value // string | string[] 🤔
if (type === 'RADIO') value // string | string[] 🤔
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -selection