I'm just wondering why the type inference for the intellisense gets lost inside an Array.isArray condition.
Consider the following snippet:
type T = {
readonly name: string;
readonly descr: string;
}
interface I{
readonly tags: ReadonlyArray<T>;
}
function Z(arg: I): void{
const { tags } = arg;
if (Array.isArray(tags)) { //hovering "tags" here shows "readonly T[]"
for (let t of tags) { //hovering "tags" here shows "any[]"
}
}
}
Z({
tags:[]
})
In other words, why the original type is not preserved from its declaration, and changes getting the isArray signature instead?
Tested on Visual Studio, and also in the playground.