Skip to content

Commit 66244f7

Browse files
committed
Don't double-check JSX calls
The JSX code path stands on its own
1 parent f20f700 commit 66244f7

File tree

4 files changed

+139
-74
lines changed

4 files changed

+139
-74
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21201,13 +21201,11 @@ namespace ts {
2120121201

2120221202
const errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } = { errors: undefined, skipLogging: true };
2120321203
if (isJsxOpeningLikeElement(node)) {
21204-
const r = checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer);
21205-
if (!r) {
21206-
if (reportErrors) {
21207-
Debug.assert(!!errorOutputContainer.errors, "has error 0");
21208-
}
21204+
if (!checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer)) {
21205+
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "jsx should have errors when reporting errors");
2120921206
return errorOutputContainer.errors || [];
2121021207
}
21208+
return undefined;
2121121209
}
2121221210
const thisType = getThisTypeOfSignature(signature);
2121321211
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
@@ -21219,7 +21217,7 @@ namespace ts {
2121921217
const errorNode = reportErrors ? (thisArgumentNode || node) : undefined;
2122021218
const headMessage = Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1;
2122121219
if (!checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer)) {
21222-
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "has error 1"); // CLEAR
21220+
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "this parameter should have errors when reporting errors");
2122321221
return errorOutputContainer.errors || [];
2122421222
}
2122521223
}
@@ -21236,7 +21234,7 @@ namespace ts {
2123621234
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
2123721235
const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
2123821236
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain, errorOutputContainer)) {
21239-
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "has error 2"); // CLEAR
21237+
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "parameter should have errors when reporting errors");
2124021238
return errorOutputContainer.errors || [];
2124121239
}
2124221240
}
@@ -21245,7 +21243,7 @@ namespace ts {
2124521243
const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, /*context*/ undefined);
2124621244
const errorNode = reportErrors ? argCount < args.length ? args[argCount] : node : undefined;
2124721245
if (!checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage, undefined, errorOutputContainer)) {
21248-
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "has error 3"); // CLEAR
21246+
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "rest parameter should have errors when reporting errors");
2124921247
return errorOutputContainer.errors || [];
2125021248
}
2125121249
}
Lines changed: 98 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
tests/cases/conformance/jsx/file.tsx(12,13): error TS2322: Type '{ extraProp: true; }' is not assignable to type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
2-
Property 'extraProp' does not exist on type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
3-
tests/cases/conformance/jsx/file.tsx(13,13): error TS2741: Property 'yy1' is missing in type '{ yy: number; }' but required in type '{ yy: number; yy1: string; }'.
4-
tests/cases/conformance/jsx/file.tsx(14,31): error TS2322: Type 'true' is not assignable to type 'string'.
5-
tests/cases/conformance/jsx/file.tsx(16,13): error TS2322: Type '{ y1: number; yy: number; yy1: string; }' is not assignable to type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
6-
Property 'y1' does not exist on type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
7-
tests/cases/conformance/jsx/file.tsx(17,13): error TS2322: Type '{ yy: boolean; yy1: string; }' is not assignable to type '{ yy: number; yy1: string; }'.
8-
Types of property 'yy' are incompatible.
9-
Type 'boolean' is not assignable to type 'number'.
10-
tests/cases/conformance/jsx/file.tsx(25,13): error TS2741: Property 'yy' is missing in type '{ extra-data: true; }' but required in type '{ yy: string; direction?: number; }'.
11-
tests/cases/conformance/jsx/file.tsx(26,40): error TS2322: Type 'string' is not assignable to type 'number'.
12-
tests/cases/conformance/jsx/file.tsx(33,32): error TS2322: Type 'string' is not assignable to type 'boolean'.
13-
tests/cases/conformance/jsx/file.tsx(34,29): error TS2322: Type 'string' is not assignable to type 'boolean'.
14-
tests/cases/conformance/jsx/file.tsx(35,29): error TS2322: Type 'string' is not assignable to type 'boolean'.
15-
tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type 'string' is not assignable to type 'boolean'.
1+
tests/cases/conformance/jsx/file.tsx(12,12): error TS2755: No suitable overload for this call.
2+
tests/cases/conformance/jsx/file.tsx(13,12): error TS2755: No suitable overload for this call.
3+
tests/cases/conformance/jsx/file.tsx(14,12): error TS2755: No suitable overload for this call.
4+
tests/cases/conformance/jsx/file.tsx(16,12): error TS2755: No suitable overload for this call.
5+
tests/cases/conformance/jsx/file.tsx(17,12): error TS2755: No suitable overload for this call.
6+
tests/cases/conformance/jsx/file.tsx(25,12): error TS2755: No suitable overload for this call.
7+
tests/cases/conformance/jsx/file.tsx(26,12): error TS2755: No suitable overload for this call.
8+
tests/cases/conformance/jsx/file.tsx(33,12): error TS2755: No suitable overload for this call.
9+
tests/cases/conformance/jsx/file.tsx(34,12): error TS2755: No suitable overload for this call.
10+
tests/cases/conformance/jsx/file.tsx(35,12): error TS2755: No suitable overload for this call.
11+
tests/cases/conformance/jsx/file.tsx(36,12): error TS2755: No suitable overload for this call.
1612

1713

1814
==== tests/cases/conformance/jsx/file.tsx (11 errors) ====
@@ -28,27 +24,49 @@ tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type 'string' is not
2824

2925
// Error
3026
const c0 = <OneThing extraProp />; // extra property;
31-
~~~~~~~~
32-
!!! error TS2322: Type '{ extraProp: true; }' is not assignable to type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
33-
!!! error TS2322: Property 'extraProp' does not exist on type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
27+
~~~~~~~~~~~~~~~~~~~~~~
28+
!!! error TS2755: No suitable overload for this call.
29+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:12:13: Overload 1 of 2, '(): Element', gave the following error.
30+
Type '{ extraProp: true; }' is not assignable to type 'IntrinsicAttributes'.
31+
Property 'extraProp' does not exist on type 'IntrinsicAttributes'.
32+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:12:13: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
33+
Type '{ extraProp: true; }' is not assignable to type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
34+
Property 'extraProp' does not exist on type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
3435
const c1 = <OneThing yy={10}/>; // missing property;
35-
~~~~~~~~
36-
!!! error TS2741: Property 'yy1' is missing in type '{ yy: number; }' but required in type '{ yy: number; yy1: string; }'.
37-
!!! related TS2728 tests/cases/conformance/jsx/file.tsx:3:43: 'yy1' is declared here.
36+
~~~~~~~~~~~~~~~~~~~
37+
!!! error TS2755: No suitable overload for this call.
38+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:13:13: Overload 1 of 2, '(): Element', gave the following error.
39+
Type '{ yy: number; }' is not assignable to type 'IntrinsicAttributes'.
40+
Property 'yy' does not exist on type 'IntrinsicAttributes'.
41+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:13:13: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
42+
Property 'yy1' is missing in type '{ yy: number; }' but required in type '{ yy: number; yy1: string; }'.
3843
const c2 = <OneThing {...obj} yy1 />; // type incompatible;
39-
~~~
40-
!!! error TS2322: Type 'true' is not assignable to type 'string'.
41-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:3:43: The expected type comes from property 'yy1' which is declared here on type 'IntrinsicAttributes & { yy: number; yy1: string; }'
44+
~~~~~~~~~~~~~~~~~~~~~~~~~
45+
!!! error TS2755: No suitable overload for this call.
46+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:14:13: Overload 1 of 2, '(): Element', gave the following error.
47+
Type '{ yy1: true; yy: number; }' is not assignable to type 'IntrinsicAttributes'.
48+
Property 'yy1' does not exist on type 'IntrinsicAttributes'.
49+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:14:31: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
50+
Type 'true' is not assignable to type 'string'.
4251
const c3 = <OneThing {...obj} {...{extra: "extra attr"}} />; // This is OK becuase all attribute are spread
4352
const c4 = <OneThing {...obj} y1={10000} />; // extra property;
44-
~~~~~~~~
45-
!!! error TS2322: Type '{ y1: number; yy: number; yy1: string; }' is not assignable to type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
46-
!!! error TS2322: Property 'y1' does not exist on type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
53+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54+
!!! error TS2755: No suitable overload for this call.
55+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:16:13: Overload 1 of 2, '(): Element', gave the following error.
56+
Type '{ y1: number; yy: number; yy1: string; }' is not assignable to type 'IntrinsicAttributes'.
57+
Property 'y1' does not exist on type 'IntrinsicAttributes'.
58+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:16:13: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
59+
Type '{ y1: number; yy: number; yy1: string; }' is not assignable to type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
60+
Property 'y1' does not exist on type 'IntrinsicAttributes & { yy: number; yy1: string; }'.
4761
const c5 = <OneThing {...obj} {...{yy: true}} />; // type incompatible;
48-
~~~~~~~~
49-
!!! error TS2322: Type '{ yy: boolean; yy1: string; }' is not assignable to type '{ yy: number; yy1: string; }'.
50-
!!! error TS2322: Types of property 'yy' are incompatible.
51-
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
62+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63+
!!! error TS2755: No suitable overload for this call.
64+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:17:13: Overload 1 of 2, '(): Element', gave the following error.
65+
Type '{ yy: boolean; yy1: string; }' has no properties in common with type 'IntrinsicAttributes'.
66+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:17:13: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
67+
Type '{ yy: boolean; yy1: string; }' is not assignable to type '{ yy: number; yy1: string; }'.
68+
Types of property 'yy' are incompatible.
69+
Type 'boolean' is not assignable to type 'number'.
5270
const c6 = <OneThing {...obj2} {...{extra: "extra attr"}} />; // Should error as there is extra attribute that doesn't match any. Current it is not
5371
const c7 = <OneThing {...obj2} yy />; // Should error as there is extra attribute that doesn't match any. Current it is not
5472

@@ -57,33 +75,64 @@ tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type 'string' is not
5775

5876
// Error
5977
const d1 = <TestingOneThing extra-data />
60-
~~~~~~~~~~~~~~~
61-
!!! error TS2741: Property 'yy' is missing in type '{ extra-data: true; }' but required in type '{ yy: string; direction?: number; }'.
62-
!!! related TS2728 tests/cases/conformance/jsx/file.tsx:22:38: 'yy' is declared here.
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
!!! error TS2755: No suitable overload for this call.
80+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:25:29: Overload 1 of 2, '(j: { "extra-data": string; }): Element', gave the following error.
81+
Type 'true' is not assignable to type 'string'.
82+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:25:13: Overload 2 of 2, '(n: { yy: string; direction?: number; }): Element', gave the following error.
83+
Property 'yy' is missing in type '{ extra-data: true; }' but required in type '{ yy: string; direction?: number; }'.
6384
const d2 = <TestingOneThing yy="hello" direction="left" />
64-
~~~~~~~~~
65-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
66-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:22:50: The expected type comes from property 'direction' which is declared here on type 'IntrinsicAttributes & { yy: string; direction?: number; }'
85+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86+
!!! error TS2755: No suitable overload for this call.
87+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:26:13: Overload 1 of 2, '(j: { "extra-data": string; }): Element', gave the following error.
88+
Type '{ yy: string; direction: string; }' is not assignable to type 'IntrinsicAttributes & { "extra-data": string; }'.
89+
Property 'yy' does not exist on type 'IntrinsicAttributes & { "extra-data": string; }'.
90+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:26:40: Overload 2 of 2, '(n: { yy: string; direction?: number; }): Element', gave the following error.
91+
Type 'string' is not assignable to type 'number'.
6792

6893
declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element;
6994
declare function TestingOptional(a: {y1?: string, y2?: number, children: JSX.Element}): JSX.Element;
7095
declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element;
7196

7297
// Error
7398
const e1 = <TestingOptional y1 y3="hello"/>
74-
~~
75-
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
76-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:64: The expected type comes from property 'y3' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
99+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100+
!!! error TS2755: No suitable overload for this call.
101+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:33:29: Overload 1 of 3, '(a: { y1?: string; y2?: number; }): Element', gave the following error.
102+
Type 'true' is not assignable to type 'string'.
103+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:33:29: Overload 2 of 3, '(a: { y1?: string; y2?: number; children: Element; }): Element', gave the following error.
104+
Type 'true' is not assignable to type 'string'.
105+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:33:32: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
106+
Type 'string' is not assignable to type 'boolean'.
77107
const e2 = <TestingOptional y1="hello" y2={1000} y3 />
78-
~~
79-
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
80-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
108+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109+
!!! error TS2755: No suitable overload for this call.
110+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:34:13: Overload 1 of 3, '(a: { y1?: string; y2?: number; }): Element', gave the following error.
111+
Type '{ y1: string; y2: number; y3: true; }' is not assignable to type 'IntrinsicAttributes & { y1?: string; y2?: number; }'.
112+
Property 'y3' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; }'.
113+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:34:13: Overload 2 of 3, '(a: { y1?: string; y2?: number; children: Element; }): Element', gave the following error.
114+
Type '{ y1: string; y2: number; y3: true; }' is not assignable to type 'IntrinsicAttributes & { y1?: string; y2?: number; children: Element; }'.
115+
Property 'y3' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; children: Element; }'.
116+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:34:29: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
117+
Type 'string' is not assignable to type 'boolean'.
81118
const e3 = <TestingOptional y1="hello" y2={1000} children="hi" />
82-
~~
83-
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
84-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
119+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120+
!!! error TS2755: No suitable overload for this call.
121+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:35:13: Overload 1 of 3, '(a: { y1?: string; y2?: number; }): Element', gave the following error.
122+
Type '{ y1: string; y2: number; children: string; }' is not assignable to type 'IntrinsicAttributes & { y1?: string; y2?: number; }'.
123+
Property 'children' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; }'.
124+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:35:50: Overload 2 of 3, '(a: { y1?: string; y2?: number; children: Element; }): Element', gave the following error.
125+
Type 'string' is not assignable to type 'Element'.
126+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:35:29: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
127+
Type 'string' is not assignable to type 'boolean'.
85128
const e4 = <TestingOptional y1="hello" y2={1000}>Hi</TestingOptional>
86-
~~
87-
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
88-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
129+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130+
!!! error TS2755: No suitable overload for this call.
131+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:36:13: Overload 1 of 3, '(a: { y1?: string; y2?: number; }): Element', gave the following error.
132+
Type '{ children: string; y1: string; y2: number; }' is not assignable to type 'IntrinsicAttributes & { y1?: string; y2?: number; }'.
133+
Property 'children' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; }'.
134+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:36:50: Overload 2 of 3, '(a: { y1?: string; y2?: number; children: Element; }): Element', gave the following error.
135+
'TestingOptional' components don't accept text as child elements. Text in JSX has the type 'string', but the expected type of 'children' is 'Element'.
136+
!!! related TS2757 tests/cases/conformance/jsx/file.tsx:36:29: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
137+
Type 'string' is not assignable to type 'boolean'.
89138

0 commit comments

Comments
 (0)