-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 3.5.1
Search Terms:
Boolean explicit annotation ignore
Code
// Errors as expected
let bothInferred = true;
if (bothInferred == false) { }
// Doesn't error as expected
let bothExplicit: boolean = true as boolean;
if (bothExplicit == false) { }
// Doesn't error as expected
let leftInferredRightExplicit = true as boolean;
if (leftInferredRightExplicit == false) { }
// Why error? Narrow rhs overrides explicit declaration.
let rigthInferredLeftExplicit: boolean = true;
if (rigthInferredLeftExplicit == false) { }
Expected behavior:
4th example above shouldn't error.
Actual behavior:
Error: This condition will always return 'false' since the types 'true' and 'false' have no overlap.
Playground Link:
Related Issues:
Tried similar patterns with other types, could not find an error.
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code