-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis
Description
TypeScript Version: 4.0.2
Search Terms: comma operator flow narrow type function
I encountered a case where type narrowing fails when using the comma operator and passing the result to a function which does type narrowing.
Code
const otherValue = () => true;
const value : number | string = null as any;
function isNumber(obj: any): obj is number {
return true; // method implementation irrelevant
}
// Good case - works
if (typeof (otherValue(), value) === 'number') {
const b = value; // number
}
// Bad case - fails
if (isNumber((otherValue(), value))) {
const b = value; // string | number , but should be number
}
Expected behavior:
I would expect the second case to also narrow down the type to number
Actual behavior:
Type is string | number
, it was not narrowed.
Related Issues:
Sounds a little related: #35484
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis