interface Bird {
age:string,
eat:()=>any
}
interface Fish {
age:string,
swim:()=>any
}
type Pet = Fish | Bird;
everything looks good so far, defining a Pet type
const pet:Pet={
age:"sd",
eat:()=>{}
}
when trying to return a Pet type, an error occurs.
function test():Pet{
return {
age:"sd",
eat:()=>{}
}
}
test().eat(); //results in a TypeScript error
I'm puzzled as to why they are both the same TypeScript type, yet test().eat()
throws an error.