Skip to content

Commit f099046

Browse files
author
Kanchalai Tanglertsampan
committed
Add tests
1 parent 4fa2312 commit f099046

10 files changed

+351
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface Prop {
9+
a: number,
10+
b: string,
11+
children: string | JSX.Element
12+
}
13+
14+
function Comp(p: Prop) {
15+
return <div>{p.b}</div>;
16+
}
17+
18+
// OK
19+
let k = <Comp a={10} b="hi" children ="lol" />;
20+
let k1 =
21+
<Comp a={10} b="hi">
22+
hi hi hi!
23+
</Comp>;
24+
let k2 =
25+
<Comp a={10} b="hi">
26+
<div>hi hi hi!</div>
27+
</Comp>;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface Prop {
9+
a: number,
10+
b: string,
11+
children: string | JSX.Element
12+
}
13+
14+
function Comp(p: Prop) {
15+
return <div>{p.b}</div>;
16+
}
17+
18+
// Error: missing children
19+
let k = <Comp a={10} b="hi" />;
20+
21+
let k1 =
22+
<Comp a={10} b="hi" children="Random" >
23+
hi hi hi!
24+
</Comp>;
25+
26+
// Error: incorrect type
27+
let k2 =
28+
<Comp a={10} b="hi">
29+
<div> My Div </div>
30+
{(name: string) => <div> My name {name} </div>}
31+
</Comp>;
32+
33+
let k3 =
34+
<Comp a={10} b="hi">
35+
<div> My Div </div>
36+
{1000000}
37+
</Comp>;
38+
39+
let k4 =
40+
<Comp a={10} b="hi" >
41+
<div> My Div </div>
42+
hi hi hi!
43+
</Comp>;
44+
45+
let k5 =
46+
<Comp a={10} b="hi" >
47+
<div> My Div </div>
48+
<div> My Div </div>
49+
</Comp>;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface IUser {
9+
Name: string;
10+
}
11+
12+
interface IFetchUserProps {
13+
children: (user: IUser) => JSX.Element;
14+
}
15+
16+
class FetchUser extends React.Component<IFetchUserProps, any> {
17+
render() {
18+
return this.state
19+
? this.props.children(this.state.result)
20+
: null;
21+
}
22+
}
23+
24+
// Ok
25+
function UserName0() {
26+
return (
27+
<FetchUser>
28+
{ user => (
29+
<h1>{ user.Name }</h1>
30+
) }
31+
</FetchUser>
32+
);
33+
}
34+
35+
function UserName1() {
36+
return (
37+
<FetchUser>
38+
39+
{ user => (
40+
<h1>{ user.Name }</h1>
41+
) }
42+
</FetchUser>
43+
);
44+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface IUser {
9+
Name: string;
10+
}
11+
12+
interface IFetchUserProps {
13+
children: (user: IUser) => JSX.Element;
14+
}
15+
16+
class FetchUser extends React.Component<IFetchUserProps, any> {
17+
render() {
18+
return this.state
19+
? this.props.children(this.state.result)
20+
: null;
21+
}
22+
}
23+
24+
// Error
25+
function UserName() {
26+
return (
27+
<FetchUser>
28+
{ user => (
29+
<h1>{ user.NAme }</h1>
30+
) }
31+
</FetchUser>
32+
);
33+
}
34+
35+
function UserName1() {
36+
return (
37+
<FetchUser>
38+
39+
40+
41+
{ user => (
42+
<h1>{ user.Name }</h1>
43+
) }
44+
{ user => (
45+
<h1>{ user.Name }</h1>
46+
) }
47+
</FetchUser>
48+
);
49+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface Prop {
9+
a: number,
10+
b: string,
11+
children: Button;
12+
}
13+
14+
class Button extends React.Component<any, any> {
15+
render() {
16+
return (<div>My Button</div>)
17+
}
18+
}
19+
20+
function Comp(p: Prop) {
21+
return <div>{p.b}</div>;
22+
}
23+
24+
// Error: no children specified
25+
let k = <Comp a={10} b="hi" />;
26+
27+
// Error: JSX.element is not the same as JSX.ElementClass
28+
let k1 =
29+
<Comp a={10} b="hi">
30+
<Button />
31+
</Comp>;
32+
let k2 =
33+
<Comp a={10} b="hi">
34+
{Button}
35+
</Comp>;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface Prop {
9+
a: number,
10+
b: string,
11+
children: JSX.Element | JSX.Element[];
12+
}
13+
14+
class Button extends React.Component<any, any> {
15+
render() {
16+
return (<div>My Button</div>)
17+
}
18+
}
19+
20+
function AnotherButton(p: any) {
21+
return <h1>Just Another Button</h1>;
22+
}
23+
24+
function Comp(p: Prop) {
25+
return <div>{p.b}</div>;
26+
}
27+
28+
// Ok
29+
let k1 =
30+
<Comp a={10} b="hi">
31+
<Button />
32+
<AnotherButton />
33+
</Comp>;
34+
35+
let k2 =
36+
<Comp a={10} b="hi">
37+
38+
39+
40+
<Button />
41+
<AnotherButton />
42+
</Comp>;
43+
44+
let k3 = <Comp a={10} b="hi"><Button />
45+
<AnotherButton />
46+
</Comp>;
47+
48+
let k4 = <Comp a={10} b="hi"><Button /></Comp>;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface Prop {
9+
a: number,
10+
b: string,
11+
children: JSX.Element | JSX.Element[];
12+
}
13+
14+
class Button extends React.Component<any, any> {
15+
render() {
16+
return (<div>My Button</div>)
17+
}
18+
}
19+
20+
function AnotherButton(p: any) {
21+
return <h1>Just Another Button</h1>;
22+
}
23+
24+
function Comp(p: Prop) {
25+
return <div>{p.b}</div>;
26+
}
27+
28+
// Error: whitespaces matters
29+
let k1 = <Comp a={10} b="hi"><Button /> <AnotherButton /></Comp>;
30+
let k2 = <Comp a={10} b="hi"><Button />
31+
<AnotherButton /> </Comp>;
32+
let k3 = <Comp a={10} b="hi"> <Button />
33+
<AnotherButton /></Comp>;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @filename: file.tsx
2+
// @jsx: preserve
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
interface Prop {
9+
a: number,
10+
b: string,
11+
children: string | JSX.Element | (string | JSX.Element)[];
12+
}
13+
14+
class Button extends React.Component<any, any> {
15+
render() {
16+
return (<div>My Button</div>)
17+
}
18+
}
19+
20+
function AnotherButton(p: any) {
21+
return <h1>Just Another Button</h1>;
22+
}
23+
24+
function Comp(p: Prop) {
25+
return <div>{p.b}</div>;
26+
}
27+
28+
// OK
29+
let k1 = <Comp a={10} b="hi"><Button /> <AnotherButton /></Comp>;
30+
let k2 = <Comp a={10} b="hi"><Button />
31+
<AnotherButton /> </Comp>;
32+
let k3 = <Comp a={10} b="hi"> <Button />
33+
<AnotherButton /></Comp>;
34+
let k4 = <Comp a={10} b="hi"><Button /> </Comp>;

tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload6.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const b6 = <MainButton {...obj2} />;
5555
const b7 = <MainButton {...{onClick: () => { console.log("hi") }}} />;
5656
const b8 = <MainButton {...{onClick() {}}} />; // OK; method declaration get retained (See GitHub #13365)
5757
const b9 = <MainButton to='/some/path' extra-prop>GO</MainButton>;
58-
const b10 = <MainButton to='/some/path' children="hi" >GO</MainButton>;
58+
const b10 = <MainButton to='/some/path' children="hi" ></MainButton>;
5959
const b11 = <MainButton onClick={(e) => {}} className="hello" data-format>Hello world</MainButton>;
6060
const b12 = <MainButton data-format="Hello world" />
6161

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path='fourslash.ts' />
2+
//@module: commonjs
3+
//@jsx: preserve
4+
5+
// @Filename: 1.tsx
6+
//// declare module JSX {
7+
//// interface Element { }
8+
//// interface IntrinsicElements {
9+
//// }
10+
//// interface ElementAttributesProperty { props; }
11+
//// }
12+
//// interface IUser {
13+
//// Name: string;
14+
//// }
15+
//// interface IFetchUserProps {
16+
//// children: (user: IUser) => any;
17+
//// }
18+
//// function FetchUser(props: IFetchUserProps) { return undefined; }
19+
//// function UserName() {
20+
//// return (
21+
//// <FetchUser>
22+
//// { user => (
23+
//// <h1>{ user./**/ }</h1>
24+
//// )}
25+
//// </FetchUser>
26+
//// );
27+
//// }
28+
29+
goTo.marker();
30+
debugger;
31+
verify.completionListContains('Name');

0 commit comments

Comments
 (0)