-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 3.1
Search Terms: type inference, type guard, narrowing, lost, assignment
Code
let a: unknown = 'x';
if (typeof a === 'string') {
// a inferred as `string`
a = a.substr(0, 5); // (method) String.substr(from: number, length?: number): string
// a inferred as `unknown`
a.length; // Failure: Object is of type 'unknown'.
}Expected behavior: This should compile without an error.
Actual behavior: Line 7 fails with: Object is of type 'unknown'.
aleclarson, hab25, tusharf5, justingrant, crutchcorn and 25 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript