I have to create a component that can be from two different types. Let's say
Type A = { a: SomeCustomType }
Type B = { b: SomeOtherDifferentType }
As far I understand, I can define that component type as
function Component<T extends A | B>(props T){ ... Stuff }
And i can call it as
const MyComponent : A = <Component a={"test"}/>
const MyComponent : B = <Component b={1231241}/>
My question here is: when coding Component, how can i navigate props, i need to do:
function Component<T extends A | B>(props T){
let data;
if(props typeof A){
data = props.a
}
if(props typeof A){
data = props.b
}
console.log(data)
}
I'm not able to use typeof since it's for primitives, but instanceOf seems for classes only. Any clues about this? What i'm doing wrong?