File: tsxStatelessFunctionComponentOverload4.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (179 lines) | stat: -rw-r--r-- 7,320 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react')
>React : typeof React

declare function OneThing(): JSX.Element;
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>JSX : any

declare function OneThing(l: {yy: number, yy1: string}): JSX.Element;
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>l : { yy: number; yy1: string; }
>yy : number
>yy1 : string
>JSX : any

let obj = {
>obj : { yy: number; yy1: string; }
>{    yy: 10,    yy1: "hello"} : { yy: number; yy1: string; }

    yy: 10,
>yy : number
>10 : 10

    yy1: "hello"
>yy1 : string
>"hello" : "hello"
}
let obj2: any;
>obj2 : any

// Error
const c0 = <OneThing extraProp />;  // extra property;
>c0 : JSX.Element
><OneThing extraProp /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>extraProp : true

const c1 = <OneThing yy={10}/>;  // missing property;
>c1 : JSX.Element
><OneThing yy={10}/> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>yy : number
>10 : 10

const c2 = <OneThing {...obj} yy1 />; // type incompatible;
>c2 : JSX.Element
><OneThing {...obj} yy1 /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>obj : { yy: number; yy1: string; }
>yy1 : true

const c3 = <OneThing {...obj} {...{extra: "extra attr"}} />;  //  This is OK becuase all attribute are spread
>c3 : JSX.Element
><OneThing {...obj} {...{extra: "extra attr"}} /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>obj : { yy: number; yy1: string; }
>{extra: "extra attr"} : { extra: string; }
>extra : string
>"extra attr" : "extra attr"

const c4 = <OneThing {...obj} y1={10000} />;  // extra property;
>c4 : JSX.Element
><OneThing {...obj} y1={10000} /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>obj : { yy: number; yy1: string; }
>y1 : number
>10000 : 10000

const c5 = <OneThing {...obj} {...{yy: true}} />;  // type incompatible;
>c5 : JSX.Element
><OneThing {...obj} {...{yy: true}} /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>obj : { yy: number; yy1: string; }
>{yy: true} : { yy: boolean; }
>yy : boolean
>true : true

const c6 = <OneThing {...obj2} {...{extra: "extra attr"}} />;  // Should error as there is extra attribute that doesn't match any. Current it is not
>c6 : JSX.Element
><OneThing {...obj2} {...{extra: "extra attr"}} /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>obj2 : any
>{extra: "extra attr"} : { extra: string; }
>extra : string
>"extra attr" : "extra attr"

const c7 = <OneThing {...obj2} yy />;  // Should error as there is extra attribute that doesn't match any. Current it is not
>c7 : JSX.Element
><OneThing {...obj2} yy /> : JSX.Element
>OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; }
>obj2 : any
>yy : true

declare function TestingOneThing(j: {"extra-data": string}): JSX.Element;
>TestingOneThing : { (j: { "extra-data": string; }): JSX.Element; (n: { yy: string; direction?: number; }): JSX.Element; }
>j : { "extra-data": string; }
>"extra-data" : string
>JSX : any

declare function TestingOneThing(n: {yy: string, direction?: number}): JSX.Element;
>TestingOneThing : { (j: { "extra-data": string; }): JSX.Element; (n: { yy: string; direction?: number; }): JSX.Element; }
>n : { yy: string; direction?: number; }
>yy : string
>direction : number
>JSX : any

// Error
const d1 = <TestingOneThing extra-data />
>d1 : JSX.Element
><TestingOneThing extra-data /> : JSX.Element
>TestingOneThing : { (j: { "extra-data": string; }): JSX.Element; (n: { yy: string; direction?: number; }): JSX.Element; }
>extra-data : true

const d2 = <TestingOneThing yy="hello" direction="left" />
>d2 : JSX.Element
><TestingOneThing yy="hello" direction="left" /> : JSX.Element
>TestingOneThing : { (j: { "extra-data": string; }): JSX.Element; (n: { yy: string; direction?: number; }): JSX.Element; }
>yy : string
>direction : string

declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element;
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>a : { y1?: string; y2?: number; }
>y1 : string
>y2 : number
>JSX : any

declare function TestingOptional(a: {y1?: string, y2?: number, children: JSX.Element}): JSX.Element;
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>a : { y1?: string; y2?: number; children: JSX.Element; }
>y1 : string
>y2 : number
>children : JSX.Element
>JSX : any
>JSX : any

declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element;
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>a : { y1: boolean; y2?: number; y3: boolean; }
>y1 : boolean
>y2 : number
>y3 : boolean
>JSX : any

// Error
const e1 = <TestingOptional y1 y3="hello"/>
>e1 : JSX.Element
><TestingOptional y1 y3="hello"/> : JSX.Element
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>y1 : true
>y3 : string

const e2 = <TestingOptional y1="hello" y2={1000} y3 />
>e2 : JSX.Element
><TestingOptional y1="hello" y2={1000} y3 /> : JSX.Element
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>y1 : string
>y2 : number
>1000 : 1000
>y3 : true

const e3 = <TestingOptional y1="hello" y2={1000} children="hi" />
>e3 : JSX.Element
><TestingOptional y1="hello" y2={1000} children="hi" /> : JSX.Element
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>y1 : string
>y2 : number
>1000 : 1000
>children : string

const e4 = <TestingOptional y1="hello" y2={1000}>Hi</TestingOptional>
>e4 : JSX.Element
><TestingOptional y1="hello" y2={1000}>Hi</TestingOptional> : JSX.Element
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }
>y1 : string
>y2 : number
>1000 : 1000
>TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; }