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
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.
π Search Terms
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.0-beta&ssl=7&ssc=20&pln=7&pc=21#code/JYOwLgpgTgZghgYwgAgILIN4ChnIDZwBGEeA-AFzIDOYUoA5gNw7JwXW0OO4D0PyAWzgBrFFAgBHAK7BxAE2RgA9shLABoOJFVQoSqFgC+WLKEixEKAEKYWBYmUo06IJr37iBSgG4oqACzh5ZAAHPRDoMABPRRU1DRAtFGg9A1xCSkIlJTwIOBBmYywYKRAEMGAlEGRgKisACjB-BkolQgArCHKASkomhhqqZBtsXHEwKShqgHJCaZrq-tdCkxKyiqrFCBpG5tdKVG7bXCX6ADo4bmQ+ZCVhFmAYZHrahtPuo9HcRT3zy-cdKlSCxjMYgA
π» Code
π Actual behavior
The type of
thing
inside the conditional isB
.π Expected behavior
The type of
thing
inside the conditional should beA & B
.Additional information about the issue
This only happens if:
A
is a "weak" type (all optional properties).A
andB
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.
https://github.com/microsoft/vscode/blob/273d65a156865def7869e2899235ea2ab9837a81/src/vs/workbench/api/common/extHostTreeViews.ts#L821
The text was updated successfully, but these errors were encountered: