You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type narrowing not applied for nested types when passing to functionΒ #62525
typeEntity=|{type: "one";name: string|null;}|{type: "two";name: string|null;}|undefined;functionnameRequired(e: {name: string}){}functionstringRequired(str: string){}functiontest(e: Entity){if(e&&e.name){stringRequired(e.name);// FailsnameRequired(e);// Which seemingly has the same types as the above, succeeds.nameRequired(eastypeofe&{name: typeofe.name});}}
π Actual behavior
Reports a type error:
Argument of type '{ type: "one"; name: string | null; } | { type: "two"; name: string | null; }' is not assignable to parameter of type '{ name: string; }'.
Type '{ type: "one"; name: string | null; }' is not assignable to type '{ name: string; }'.
Types of property 'name' are incompatible.
Type 'string | null' is not assignable to type 'string'.
Type 'null' is not assignable to type 'string'.
Martin Johns (@MartinJohns), thanks for the house-keeping! In fact, the issue you mentioned indeed contains a comment which has a quite similar case to mine here: #42384 (comment)
Activity
MartinJohns commentedon Oct 2, 2025
Duplicate of #42384 and many many more.
SimonSimCity commentedon Oct 2, 2025
Martin Johns (@MartinJohns), thanks for the house-keeping! In fact, the issue you mentioned indeed contains a comment which has a quite similar case to mine here: #42384 (comment)