I am encountering an issue with the following code snippet:
const f = (x: unknown) => {
if (!x || !Array.isArray(x)) {
throw new Error("bad");
}
for (const y of x) {
if (!y || typeof y !== "object") {
throw new Error("bad");
}
y // y does intellisense think this has type `any`
}
};
While working in VS Code, I have noticed that intellisense is identifying the final y
as type any
. I was expecting it to be recognized as type object
. Why is intellisense interpreting this as 'any' and how can I structure my code to ensure that intellisense recognizes the second y
as type object
?