forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextuallyTypedJsxAttribute.types
More file actions
95 lines (78 loc) · 2.71 KB
/
contextuallyTypedJsxAttribute.types
File metadata and controls
95 lines (78 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//// [tests/cases/compiler/contextuallyTypedJsxAttribute.ts] ////
=== index.tsx ===
interface Elements {
foo: { callback?: (value: number) => void };
>foo : { callback?: ((value: number) => void) | undefined; }
> : ^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^
>callback : ((value: number) => void) | undefined
> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^
>value : number
> : ^^^^^^
bar: { callback?: (value: string) => void };
>bar : { callback?: ((value: string) => void) | undefined; }
> : ^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^
>callback : ((value: string) => void) | undefined
> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^
>value : string
> : ^^^^^^
}
type Props<C extends keyof Elements> = { as?: C } & Elements[C];
>Props : Props<C>
> : ^^^^^^^^
>as : C | undefined
> : ^^^^^^^^^^^^^
declare function Test<C extends keyof Elements>(props: Props<C>): null;
>Test : <C extends keyof Elements>(props: Props<C>) => null
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>props : Props<C>
> : ^^^^^^^^
<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
> : ^^^^^^
/>;