-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixed issue with spreading a generic call expression into generic JSX and gather intra expression inference sites from spread expressions #53444
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
Merged
Merged
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
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
47 changes: 47 additions & 0 deletions
47
tests/baselines/reference/jsxGenericComponentWithSpreadingResultOfGenericFunction.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,47 @@ | ||
=== tests/cases/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
// repro #51577 | ||
|
||
declare function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; | ||
>omit : Symbol(omit, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 0, 0), Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 84)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 22)) | ||
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 24)) | ||
>names : Symbol(names, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 43)) | ||
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 24)) | ||
>obj : Symbol(obj, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 63)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 22)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 22)) | ||
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 24)) | ||
|
||
declare function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; | ||
>omit : Symbol(omit, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 0, 0), Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 84)) | ||
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 22)) | ||
>names : Symbol(names, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 40)) | ||
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 22)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 63)) | ||
>obj : Symbol(obj, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 66)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 63)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 63)) | ||
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 22)) | ||
|
||
declare const otherProps: { bar: string, qwe: boolean } | ||
>otherProps : Symbol(otherProps, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 13)) | ||
>bar : Symbol(bar, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 27)) | ||
>qwe : Symbol(qwe, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 40)) | ||
|
||
declare function GenericComponent<T>(props: T): null | ||
>GenericComponent : Symbol(GenericComponent, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 55)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 9, 34)) | ||
>props : Symbol(props, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 9, 37)) | ||
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 9, 34)) | ||
|
||
<GenericComponent {...omit(['bar'], otherProps)} />; // no error | ||
>GenericComponent : Symbol(GenericComponent, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 55)) | ||
>omit : Symbol(omit, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 0, 0), Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 84)) | ||
>otherProps : Symbol(otherProps, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 13)) | ||
|
||
|
||
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/jsxGenericComponentWithSpreadingResultOfGenericFunction.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,35 @@ | ||
=== tests/cases/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
// repro #51577 | ||
|
||
declare function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; | ||
>omit : { <T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; <K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; } | ||
>names : readonly K[] | ||
>obj : T | ||
|
||
declare function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; | ||
>omit : { <T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; <K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; } | ||
>names : readonly K[] | ||
>obj : T | ||
|
||
declare const otherProps: { bar: string, qwe: boolean } | ||
>otherProps : { bar: string; qwe: boolean; } | ||
>bar : string | ||
>qwe : boolean | ||
|
||
declare function GenericComponent<T>(props: T): null | ||
>GenericComponent : <T>(props: T) => null | ||
>props : T | ||
|
||
<GenericComponent {...omit(['bar'], otherProps)} />; // no error | ||
><GenericComponent {...omit(['bar'], otherProps)} /> : JSX.Element | ||
>GenericComponent : <T>(props: T) => null | ||
>omit(['bar'], otherProps) : Omit<{ bar: string; qwe: boolean; }, "bar"> | ||
>omit : { <T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; <K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; } | ||
>['bar'] : "bar"[] | ||
>'bar' : "bar" | ||
>otherProps : { bar: string; qwe: boolean; } | ||
|
||
|
||
|
18 changes: 18 additions & 0 deletions
18
tests/cases/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx
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,18 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
// @jsx: preserve | ||
|
||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
// repro #51577 | ||
|
||
declare function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; | ||
declare function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; | ||
|
||
declare const otherProps: { bar: string, qwe: boolean } | ||
|
||
declare function GenericComponent<T>(props: T): null | ||
|
||
<GenericComponent {...omit(['bar'], otherProps)} />; // no error | ||
|
||
|
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
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.
This forwards
CheckMode.Inferential
as that's a requirement foraddIntraExpressionInferenceSite
to be calledThere 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.
Dub question, but, why not just pass check mode alone? (I wish we made the parameter required everywhere...)
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.
That’s a question i can’t answer. I just figured out that the original issue was caused by the fact that it was passed down and that it was inconsistent with regular calls. So I unified both paths to work the same.
that other issue with spreads and intra expression inferences was accidentally discovered - it wasn’t exactly what was reported as broken for lack of this feature in JSX. It just was an example of a workaround and when I was fixing that issue I just copy pasted all of the examples from the issue. If not that, it’s likely that we would never know about this being broken - although in context of JSX there are some people who prefer to spread object literals (which is not common with regular calls, at least not in such a simple form). @weswigham mentioned in the comment that this case looked alright to him and that we don't want to break it… so here we are :)