-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
TypeScript Version: 4.2.0-dev.20201121
Search Terms: comma operator flow narrow type function property access
I encountered a case where type narrowing fails when using the comma operator and accessing a property of the last operator in the chain afterwards. It does narrow the type correctly when using the value directly, but when using that value with a comma operator it does not.
Code
const otherValue = () => true;
const value : {inner: number | string} = null as any;
function isNumber(obj: any): obj is number {
return true; // method implementation irrelevant
}
if (typeof (otherValue(), value).inner === 'number') {
const a = value.inner; // number
const b = (otherValue(), value).inner; // string | number , but should be number
}
if (isNumber((otherValue(), value).inner)) {
const a = value.inner; // number
const b = (otherValue(), value).inner; // string | number , but should be number
}
Expected behavior:
I would expect the second case (variable b
) to also narrow down the type to number
Actual behavior:
Type is string | number
, it was not narrowed.
Related Issues:
#41183
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.