Skip to content

Commit 61a8e2c

Browse files
authored
Add a test for an error on required JSX children when an empty JSX expression is used (#53113)
1 parent 79ef86f commit 61a8e2c

4 files changed

+175
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
tests/cases/compiler/jsxEmptyExpressionNotCountedAsChild2.tsx(28,2): error TS2322: Type '{ __children__: never[]; }' is not assignable to type '{ bar?: number | undefined; } & { __children__: () => number; }'.
2+
Type '{ __children__: never[]; }' is not assignable to type '{ __children__: () => number; }'.
3+
Types of property '__children__' are incompatible.
4+
Type 'never[]' is not assignable to type '() => number'.
5+
Type 'never[]' provides no match for the signature '(): number'.
6+
7+
8+
==== tests/cases/compiler/jsxEmptyExpressionNotCountedAsChild2.tsx (1 errors) ====
9+
// repro from #38108
10+
11+
export {}
12+
13+
declare global {
14+
namespace JSX {
15+
type Element = any;
16+
interface ElementAttributesProperty {
17+
__properties__: {};
18+
}
19+
interface IntrinsicElements {
20+
[key: string]: string;
21+
}
22+
interface ElementChildrenAttribute {
23+
__children__: {};
24+
}
25+
}
26+
}
27+
28+
interface MockComponentInterface {
29+
new (): {
30+
__properties__: { bar?: number } & { __children__: () => number };
31+
};
32+
}
33+
34+
declare const MockComponent: MockComponentInterface;
35+
36+
<MockComponent>{}</MockComponent>; // error
37+
~~~~~~~~~~~~~
38+
!!! error TS2322: Type '{ __children__: never[]; }' is not assignable to type '{ bar?: number | undefined; } & { __children__: () => number; }'.
39+
!!! error TS2322: Type '{ __children__: never[]; }' is not assignable to type '{ __children__: () => number; }'.
40+
!!! error TS2322: Types of property '__children__' are incompatible.
41+
!!! error TS2322: Type 'never[]' is not assignable to type '() => number'.
42+
!!! error TS2322: Type 'never[]' provides no match for the signature '(): number'.
43+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/compiler/jsxEmptyExpressionNotCountedAsChild2.tsx ===
2+
// repro from #38108
3+
4+
export {}
5+
6+
declare global {
7+
>global : Symbol(global, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 2, 9))
8+
9+
namespace JSX {
10+
>JSX : Symbol(JSX, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 4, 16))
11+
12+
type Element = any;
13+
>Element : Symbol(Element, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 5, 19))
14+
15+
interface ElementAttributesProperty {
16+
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 6, 27))
17+
18+
__properties__: {};
19+
>__properties__ : Symbol(ElementAttributesProperty.__properties__, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 7, 45))
20+
}
21+
interface IntrinsicElements {
22+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 9, 9))
23+
24+
[key: string]: string;
25+
>key : Symbol(key, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 11, 13))
26+
}
27+
interface ElementChildrenAttribute {
28+
>ElementChildrenAttribute : Symbol(ElementChildrenAttribute, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 12, 9))
29+
30+
__children__: {};
31+
>__children__ : Symbol(ElementChildrenAttribute.__children__, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 13, 44))
32+
}
33+
}
34+
}
35+
36+
interface MockComponentInterface {
37+
>MockComponentInterface : Symbol(MockComponentInterface, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 17, 1))
38+
39+
new (): {
40+
__properties__: { bar?: number } & { __children__: () => number };
41+
>__properties__ : Symbol(__properties__, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 20, 10))
42+
>bar : Symbol(bar, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 21, 25))
43+
>__children__ : Symbol(__children__, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 21, 44))
44+
45+
};
46+
}
47+
48+
declare const MockComponent: MockComponentInterface;
49+
>MockComponent : Symbol(MockComponent, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 25, 13))
50+
>MockComponentInterface : Symbol(MockComponentInterface, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 17, 1))
51+
52+
<MockComponent>{}</MockComponent>; // error
53+
>MockComponent : Symbol(MockComponent, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 25, 13))
54+
>MockComponent : Symbol(MockComponent, Decl(jsxEmptyExpressionNotCountedAsChild2.tsx, 25, 13))
55+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
=== tests/cases/compiler/jsxEmptyExpressionNotCountedAsChild2.tsx ===
2+
// repro from #38108
3+
4+
export {}
5+
6+
declare global {
7+
>global : any
8+
9+
namespace JSX {
10+
type Element = any;
11+
>Element : any
12+
13+
interface ElementAttributesProperty {
14+
__properties__: {};
15+
>__properties__ : {}
16+
}
17+
interface IntrinsicElements {
18+
[key: string]: string;
19+
>key : string
20+
}
21+
interface ElementChildrenAttribute {
22+
__children__: {};
23+
>__children__ : {}
24+
}
25+
}
26+
}
27+
28+
interface MockComponentInterface {
29+
new (): {
30+
__properties__: { bar?: number } & { __children__: () => number };
31+
>__properties__ : { bar?: number | undefined; } & { __children__: () => number; }
32+
>bar : number | undefined
33+
>__children__ : () => number
34+
35+
};
36+
}
37+
38+
declare const MockComponent: MockComponentInterface;
39+
>MockComponent : MockComponentInterface
40+
41+
<MockComponent>{}</MockComponent>; // error
42+
><MockComponent>{}</MockComponent> : any
43+
>MockComponent : MockComponentInterface
44+
>MockComponent : MockComponentInterface
45+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @jsx: preserve
4+
5+
// repro from #38108
6+
7+
export {}
8+
9+
declare global {
10+
namespace JSX {
11+
type Element = any;
12+
interface ElementAttributesProperty {
13+
__properties__: {};
14+
}
15+
interface IntrinsicElements {
16+
[key: string]: string;
17+
}
18+
interface ElementChildrenAttribute {
19+
__children__: {};
20+
}
21+
}
22+
}
23+
24+
interface MockComponentInterface {
25+
new (): {
26+
__properties__: { bar?: number } & { __children__: () => number };
27+
};
28+
}
29+
30+
declare const MockComponent: MockComponentInterface;
31+
32+
<MockComponent>{}</MockComponent>; // error

0 commit comments

Comments
 (0)