dprks
dprks

Reputation: 1

Reassign param type - typescript

type T0 = {
  a: string
  b: string
}
type T1 = Omit<T0, 'b'>
function func({ param }: { param: T0 | T1 }) {
    if (param.hasOwnProperty('b')) { /* reassign type */ }
  return param.b
}

Is there a possibility to reassign type for param from T0 | T1 to T0?

Upvotes: 0

Views: 40

Answers (1)

K1games
K1games

Reputation: 131

I believe you should just put optional b and use just one type

type T0 = {a:string, b:?string }

Upvotes: 1

Related Questions