Repository navigation
Skip discriminant lookups for unions that cannot be narrowed #64934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mateusz Burzyński (Andarist)
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
Andarist:experiment/discriminable-union-gate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+217
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...stdata/baselines/reference/compiler/deprecatedPropertyInNullableContextualType.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| jsxAttributes.tsx(10,35): suggestion TS6385: 'value' is deprecated. | ||
| jsxAttributes.tsx(11,29): suggestion TS6385: 'value' is deprecated. | ||
| objectLiteral.ts(5,41): suggestion TS6385: 'value' is deprecated. | ||
| objectLiteral.ts(6,26): suggestion TS6385: 'value' is deprecated. | ||
|
|
||
|
|
||
| ==== objectLiteral.ts (2 errors) ==== | ||
| interface Options { | ||
| /** @deprecated use other */ | ||
| value: number; | ||
| } | ||
| const nullable: Options | undefined = { value: 1 }; | ||
| ~~~~~ | ||
| !!! suggestion TS6385: 'value' is deprecated. | ||
| !!! related TS2798 objectLiteral.ts:2:9: The declaration was marked as deprecated here. | ||
| const plain: Options = { value: 1 }; | ||
| ~~~~~ | ||
| !!! suggestion TS6385: 'value' is deprecated. | ||
| !!! related TS2798 objectLiteral.ts:2:9: The declaration was marked as deprecated here. | ||
|
|
||
| ==== jsxAttributes.tsx (2 errors) ==== | ||
| declare namespace JSX { | ||
| interface Element {} | ||
| } | ||
| interface Props { | ||
| /** @deprecated use other */ | ||
| value: number; | ||
| } | ||
| declare function Nullable(props: Props | undefined): JSX.Element; | ||
| declare function Plain(props: Props): JSX.Element; | ||
| const nullableElement = <Nullable value={1} />; | ||
| ~~~~~ | ||
| !!! suggestion TS6385: 'value' is deprecated. | ||
| !!! related TS2798 jsxAttributes.tsx:5:9: The declaration was marked as deprecated here. | ||
| const plainElement = <Plain value={1} />; | ||
| ~~~~~ | ||
| !!! suggestion TS6385: 'value' is deprecated. | ||
| !!! related TS2798 jsxAttributes.tsx:5:9: The declaration was marked as deprecated here. | ||
|
|
58 changes: 58 additions & 0 deletions
58
tsc/testdata/baselines/reference/compiler/deprecatedPropertyInNullableContextualType.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //// [tests/cases/compiler/deprecatedPropertyInNullableContextualType.ts] //// | ||
|
|
||
| === objectLiteral.ts === | ||
| interface Options { | ||
| >Options : Symbol(Options, Decl(objectLiteral.ts, 0, 0)) | ||
|
|
||
| /** @deprecated use other */ | ||
| value: number; | ||
| >value : Symbol(Options.value, Decl(objectLiteral.ts, 0, 19)) | ||
| } | ||
| const nullable: Options | undefined = { value: 1 }; | ||
| >nullable : Symbol(nullable, Decl(objectLiteral.ts, 4, 5)) | ||
| >Options : Symbol(Options, Decl(objectLiteral.ts, 0, 0)) | ||
| >value : Symbol(value, Decl(objectLiteral.ts, 4, 39)) | ||
|
|
||
| const plain: Options = { value: 1 }; | ||
| >plain : Symbol(plain, Decl(objectLiteral.ts, 5, 5)) | ||
| >Options : Symbol(Options, Decl(objectLiteral.ts, 0, 0)) | ||
| >value : Symbol(value, Decl(objectLiteral.ts, 5, 24)) | ||
|
|
||
| === jsxAttributes.tsx === | ||
| declare namespace JSX { | ||
| >JSX : Symbol(JSX, Decl(jsxAttributes.tsx, 0, 0)) | ||
|
|
||
| interface Element {} | ||
| >Element : Symbol(Element, Decl(jsxAttributes.tsx, 0, 23)) | ||
| } | ||
| interface Props { | ||
| >Props : Symbol(Props, Decl(jsxAttributes.tsx, 2, 1)) | ||
|
|
||
| /** @deprecated use other */ | ||
| value: number; | ||
| >value : Symbol(Props.value, Decl(jsxAttributes.tsx, 3, 17)) | ||
| } | ||
| declare function Nullable(props: Props | undefined): JSX.Element; | ||
| >Nullable : Symbol(Nullable, Decl(jsxAttributes.tsx, 6, 1)) | ||
| >props : Symbol(props, Decl(jsxAttributes.tsx, 7, 26)) | ||
| >Props : Symbol(Props, Decl(jsxAttributes.tsx, 2, 1)) | ||
| >JSX : Symbol(JSX, Decl(jsxAttributes.tsx, 0, 0)) | ||
| >Element : Symbol(JSX.Element, Decl(jsxAttributes.tsx, 0, 23)) | ||
|
|
||
| declare function Plain(props: Props): JSX.Element; | ||
| >Plain : Symbol(Plain, Decl(jsxAttributes.tsx, 7, 65)) | ||
| >props : Symbol(props, Decl(jsxAttributes.tsx, 8, 23)) | ||
| >Props : Symbol(Props, Decl(jsxAttributes.tsx, 2, 1)) | ||
| >JSX : Symbol(JSX, Decl(jsxAttributes.tsx, 0, 0)) | ||
| >Element : Symbol(JSX.Element, Decl(jsxAttributes.tsx, 0, 23)) | ||
|
|
||
| const nullableElement = <Nullable value={1} />; | ||
| >nullableElement : Symbol(nullableElement, Decl(jsxAttributes.tsx, 9, 5)) | ||
| >Nullable : Symbol(Nullable, Decl(jsxAttributes.tsx, 6, 1)) | ||
| >value : Symbol(value, Decl(jsxAttributes.tsx, 9, 33)) | ||
|
|
||
| const plainElement = <Plain value={1} />; | ||
| >plainElement : Symbol(plainElement, Decl(jsxAttributes.tsx, 10, 5)) | ||
| >Plain : Symbol(Plain, Decl(jsxAttributes.tsx, 7, 65)) | ||
| >value : Symbol(value, Decl(jsxAttributes.tsx, 10, 27)) | ||
|
|
53 changes: 53 additions & 0 deletions
53
tsc/testdata/baselines/reference/compiler/deprecatedPropertyInNullableContextualType.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //// [tests/cases/compiler/deprecatedPropertyInNullableContextualType.ts] //// | ||
|
|
||
| === objectLiteral.ts === | ||
| interface Options { | ||
| /** @deprecated use other */ | ||
| value: number; | ||
| >value : number | ||
| } | ||
| const nullable: Options | undefined = { value: 1 }; | ||
| >nullable : Options | undefined | ||
| >{ value: 1 } : { value: number; } | ||
| >value : number | ||
| >1 : 1 | ||
|
|
||
| const plain: Options = { value: 1 }; | ||
| >plain : Options | ||
| >{ value: 1 } : { value: number; } | ||
| >value : number | ||
| >1 : 1 | ||
|
|
||
| === jsxAttributes.tsx === | ||
| declare namespace JSX { | ||
| interface Element {} | ||
| } | ||
| interface Props { | ||
| /** @deprecated use other */ | ||
| value: number; | ||
| >value : number | ||
| } | ||
| declare function Nullable(props: Props | undefined): JSX.Element; | ||
| >Nullable : (props: Props | undefined) => JSX.Element | ||
| >props : Props | undefined | ||
| >JSX : any | ||
|
|
||
| declare function Plain(props: Props): JSX.Element; | ||
| >Plain : (props: Props) => JSX.Element | ||
| >props : Props | ||
| >JSX : any | ||
|
|
||
| const nullableElement = <Nullable value={1} />; | ||
| >nullableElement : JSX.Element | ||
| ><Nullable value={1} /> : JSX.Element | ||
| >Nullable : (props: Props | undefined) => JSX.Element | ||
| >value : number | ||
| >1 : 1 | ||
|
|
||
| const plainElement = <Plain value={1} />; | ||
| >plainElement : JSX.Element | ||
| ><Plain value={1} /> : JSX.Element | ||
| >Plain : (props: Props) => JSX.Element | ||
| >value : number | ||
| >1 : 1 | ||
|
|
25 changes: 25 additions & 0 deletions
25
tsc/testdata/tests/cases/compiler/deprecatedPropertyInNullableContextualType.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // @strict: true | ||
| // @jsx: preserve | ||
| // @captureSuggestions: true | ||
| // @noEmit: true | ||
|
|
||
| // @filename: objectLiteral.ts | ||
| interface Options { | ||
| /** @deprecated use other */ | ||
| value: number; | ||
| } | ||
| const nullable: Options | undefined = { value: 1 }; | ||
| const plain: Options = { value: 1 }; | ||
|
|
||
| // @filename: jsxAttributes.tsx | ||
| declare namespace JSX { | ||
| interface Element {} | ||
| } | ||
| interface Props { | ||
| /** @deprecated use other */ | ||
| value: number; | ||
| } | ||
| declare function Nullable(props: Props | undefined): JSX.Element; | ||
| declare function Plain(props: Props): JSX.Element; | ||
| const nullableElement = <Nullable value={1} />; | ||
| const plainElement = <Plain value={1} />; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I measured this and couldn't find this to make any different for any project. Also, the result is node-independent so the per-node cache wouldnt fit this all too well. I could add a second type-based cache but I couldn't prove anyhow it would actually be worth it.