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
Narrowing by type predicate fails to produce intersection type with weak typeΒ #58518
interfaceA{label?: string;a?: string;// make required to eliminate error}interfaceB{label?: string;// remove shared property to eliminate errorb: boolean;}functionisB(thing: object): thing is B{return'b'inthing;}functiontest(thing: A){thing.a;// okif(isB(thing)){thing.a;// error?}}
π Actual behavior
The type of thing inside the conditional is B.
π Expected behavior
The type of thing inside the conditional should be A & B.
Additional information about the issue
This only happens if:
A is a "weak" type (all optional properties).
A and B have at least one overlapping property.
If either of these isn't the case, then you get the expected intersection type:
This came up in vscode while testing #58495 (comment). The issue is there already but is latent because control flow analysis can't see that a type predicate becomes a type assertion without that PR.
Activity