If I want to check if a given function parameter fits one type, using a type guard function is fine.
What if the param fits more than one type like in this simplified example:
type MyType = {
timestamp: number;
value: number;
}
function isMyType(param):param is MyType(){
return (
param?.timestamp !== undefined &&
param?.value !== undefined &&
typeof param.timestamp === 'number' &&
typeof param.value === 'number'
)
}
const param:any = {
timestamp:0,
value:0,
last:{
timestamp:1,
value:2
}
};
if(isMyType(param) && isMyType(param.last))
Here, my IDE will say the second isMyType as a never because it assumes param only fits MyType . Is there a way to replace the is in the predicate to mean it fits the type but doesnt mean its exclusively this type? I know I could make it is MyType & {[key: string]: any;]} but I'm not sure I like this eighter.