When actions
is defined in the object, I want type C
to be B
, when it's not defined, I want type C
to be A
, how to implement such type/interface?
interface A {
label: string
prop: string
}
interface B {
label?: string
actions: string[]
}
// Pseudocode
type C = actions ? B : A
const c1: C = { // type A
label: 'c1',
prop: 'c1',
}
const c2: C = { // type B
label: 'c2',
actions: ['c2'],
}