-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass contextFlags when getting contextual type of JSX elements/attrib…
…utes (#49707)
- Loading branch information
1 parent
1eb276f
commit b379e7f
Showing
5 changed files
with
202 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/contextuallyTypedJsxAttribute.js
This file contains 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,32 @@ | ||
//// [index.tsx] | ||
interface Elements { | ||
foo: { callback?: (value: number) => void }; | ||
bar: { callback?: (value: string) => void }; | ||
} | ||
|
||
type Props<C extends keyof Elements> = { as?: C } & Elements[C]; | ||
declare function Test<C extends keyof Elements>(props: Props<C>): null; | ||
|
||
<Test | ||
as="bar" | ||
callback={(value) => {}} | ||
/>; | ||
|
||
Test({ | ||
as: "bar", | ||
callback: (value) => {}, | ||
}); | ||
|
||
<Test<'bar'> | ||
as="bar" | ||
callback={(value) => {}} | ||
/>; | ||
|
||
|
||
//// [index.jsx] | ||
<Test as="bar" callback={function (value) { }}/>; | ||
Test({ | ||
as: "bar", | ||
callback: function (value) { } | ||
}); | ||
<Test as="bar" callback={function (value) { }}/>; |
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/contextuallyTypedJsxAttribute.symbols
This file contains 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,68 @@ | ||
=== tests/cases/compiler/index.tsx === | ||
interface Elements { | ||
>Elements : Symbol(Elements, Decl(index.tsx, 0, 0)) | ||
|
||
foo: { callback?: (value: number) => void }; | ||
>foo : Symbol(Elements.foo, Decl(index.tsx, 0, 20)) | ||
>callback : Symbol(callback, Decl(index.tsx, 1, 8)) | ||
>value : Symbol(value, Decl(index.tsx, 1, 21)) | ||
|
||
bar: { callback?: (value: string) => void }; | ||
>bar : Symbol(Elements.bar, Decl(index.tsx, 1, 46)) | ||
>callback : Symbol(callback, Decl(index.tsx, 2, 8)) | ||
>value : Symbol(value, Decl(index.tsx, 2, 21)) | ||
} | ||
|
||
type Props<C extends keyof Elements> = { as?: C } & Elements[C]; | ||
>Props : Symbol(Props, Decl(index.tsx, 3, 1)) | ||
>C : Symbol(C, Decl(index.tsx, 5, 11)) | ||
>Elements : Symbol(Elements, Decl(index.tsx, 0, 0)) | ||
>as : Symbol(as, Decl(index.tsx, 5, 40)) | ||
>C : Symbol(C, Decl(index.tsx, 5, 11)) | ||
>Elements : Symbol(Elements, Decl(index.tsx, 0, 0)) | ||
>C : Symbol(C, Decl(index.tsx, 5, 11)) | ||
|
||
declare function Test<C extends keyof Elements>(props: Props<C>): null; | ||
>Test : Symbol(Test, Decl(index.tsx, 5, 64)) | ||
>C : Symbol(C, Decl(index.tsx, 6, 22)) | ||
>Elements : Symbol(Elements, Decl(index.tsx, 0, 0)) | ||
>props : Symbol(props, Decl(index.tsx, 6, 48)) | ||
>Props : Symbol(Props, Decl(index.tsx, 3, 1)) | ||
>C : Symbol(C, Decl(index.tsx, 6, 22)) | ||
|
||
<Test | ||
>Test : Symbol(Test, Decl(index.tsx, 5, 64)) | ||
|
||
as="bar" | ||
>as : Symbol(as, Decl(index.tsx, 8, 5)) | ||
|
||
callback={(value) => {}} | ||
>callback : Symbol(callback, Decl(index.tsx, 9, 10)) | ||
>value : Symbol(value, Decl(index.tsx, 10, 13)) | ||
|
||
/>; | ||
|
||
Test({ | ||
>Test : Symbol(Test, Decl(index.tsx, 5, 64)) | ||
|
||
as: "bar", | ||
>as : Symbol(as, Decl(index.tsx, 13, 6)) | ||
|
||
callback: (value) => {}, | ||
>callback : Symbol(callback, Decl(index.tsx, 14, 12)) | ||
>value : Symbol(value, Decl(index.tsx, 15, 13)) | ||
|
||
}); | ||
|
||
<Test<'bar'> | ||
>Test : Symbol(Test, Decl(index.tsx, 5, 64)) | ||
|
||
as="bar" | ||
>as : Symbol(as, Decl(index.tsx, 18, 12)) | ||
|
||
callback={(value) => {}} | ||
>callback : Symbol(callback, Decl(index.tsx, 19, 10)) | ||
>value : Symbol(value, Decl(index.tsx, 20, 13)) | ||
|
||
/>; | ||
|
66 changes: 66 additions & 0 deletions
66
tests/baselines/reference/contextuallyTypedJsxAttribute.types
This file contains 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,66 @@ | ||
=== tests/cases/compiler/index.tsx === | ||
interface Elements { | ||
foo: { callback?: (value: number) => void }; | ||
>foo : { callback?: (value: number) => void; } | ||
>callback : (value: number) => void | ||
>value : number | ||
|
||
bar: { callback?: (value: string) => void }; | ||
>bar : { callback?: (value: string) => void; } | ||
>callback : (value: string) => void | ||
>value : string | ||
} | ||
|
||
type Props<C extends keyof Elements> = { as?: C } & Elements[C]; | ||
>Props : Props<C> | ||
>as : C | ||
|
||
declare function Test<C extends keyof Elements>(props: Props<C>): null; | ||
>Test : <C extends keyof Elements>(props: Props<C>) => null | ||
>props : Props<C> | ||
>null : null | ||
|
||
<Test | ||
><Test as="bar" callback={(value) => {}}/> : error | ||
>Test : <C extends keyof Elements>(props: Props<C>) => null | ||
|
||
as="bar" | ||
>as : "bar" | ||
|
||
callback={(value) => {}} | ||
>callback : (value: string) => void | ||
>(value) => {} : (value: string) => void | ||
>value : string | ||
|
||
/>; | ||
|
||
Test({ | ||
>Test({ as: "bar", callback: (value) => {},}) : null | ||
>Test : <C extends keyof Elements>(props: Props<C>) => null | ||
>{ as: "bar", callback: (value) => {},} : { as: "bar"; callback: (value: string) => void; } | ||
|
||
as: "bar", | ||
>as : "bar" | ||
>"bar" : "bar" | ||
|
||
callback: (value) => {}, | ||
>callback : (value: string) => void | ||
>(value) => {} : (value: string) => void | ||
>value : string | ||
|
||
}); | ||
|
||
<Test<'bar'> | ||
><Test<'bar'> as="bar" callback={(value) => {}}/> : error | ||
>Test : <C extends keyof Elements>(props: Props<C>) => null | ||
|
||
as="bar" | ||
>as : "bar" | ||
|
||
callback={(value) => {}} | ||
>callback : (value: string) => void | ||
>(value) => {} : (value: string) => void | ||
>value : string | ||
|
||
/>; | ||
|
This file contains 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,26 @@ | ||
// @jsx: preserve | ||
// @noImplicitAny: true | ||
|
||
// @filename: index.tsx | ||
interface Elements { | ||
foo: { callback?: (value: number) => void }; | ||
bar: { callback?: (value: string) => void }; | ||
} | ||
|
||
type Props<C extends keyof Elements> = { as?: C } & Elements[C]; | ||
declare function Test<C extends keyof Elements>(props: Props<C>): null; | ||
|
||
<Test | ||
as="bar" | ||
callback={(value) => {}} | ||
/>; | ||
|
||
Test({ | ||
as: "bar", | ||
callback: (value) => {}, | ||
}); | ||
|
||
<Test<'bar'> | ||
as="bar" | ||
callback={(value) => {}} | ||
/>; |