type Cat = {
pet: string;
shout: (phrase: string) => void;
};
type Dog = {
pet: string[];
shout: (phrases: string[]) => void;
};
const me: Cat | Dog = {
pet: ["cat", "dog"],
shout: (n) => {
console.log(n.length);
},
};
I am getting Parameter 'n' implicitly has an 'any' type.ts(7006), even though it should be able to infer that n is a string[] based on the fact that pet property is string[] therefore it narrows down the type to Dog
Narrowing works fine if the pet property is a string literal. Can typescript not narrow based on property type?