-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 2.0.3
Code
let list = [1, '2'];
for (let i = 0; i < list.length; i++) {
const j = i;
if (typeof list[j] === 'string') {
console.log(list[j].charAt(0)); // Property 'charAt' does not exist on type 'string | number'
}
}
Expected behavior:
Successful compilation, since the type of list[j]
is made clear with type guard
Actual behavior:
error TS2339: Property 'charAt' does not exist on type 'string | number'
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed