-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 2.2.2 with --strictNullChecks
Code
let test: string;
const obj1: {val: string|number} = {val: ''};
if (typeof obj1.val === 'string') {
test = obj1.val; // => Works fine
}
const obj2: {[k: string]: string|number} = {val: ''};
if (typeof obj2.val === 'string') {
test = obj2.val; // => Type 'string | number' is not assignable to type 'string'
}
Expected behavior:
Type guards to work on key/value objects
Actual behavior:
Can't infer the correct type after check
aluanhaddad
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript