Skip to content

JSX errors use JSX terminology #24523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10716,7 +10716,7 @@ namespace ts {
const intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
if (intrinsicAttributes !== errorType && intrinsicClassAttributes !== errorType &&
(contains(targetTypes, intrinsicAttributes) || contains(targetTypes, intrinsicClassAttributes))) {
// do not report top error
// only report an error when the target isn't the intersection type with Intrinsic[Class]Attributes
return result;
}
}
Expand Down Expand Up @@ -11281,7 +11281,12 @@ namespace ts {
const unmatchedProperty = getUnmatchedProperty(source, target, requireOptionalProperties);
if (unmatchedProperty) {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(unmatchedProperty), typeToString(source));
if (getObjectFlags(source) & ObjectFlags.JsxAttributes) {
reportError(Diagnostics.Property_0_is_missing_in_the_provided_JSX_attributes, symbolToString(unmatchedProperty));
}
else {
reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(unmatchedProperty), typeToString(source));
}
}
return Ternary.False;
}
Expand Down
4 changes: 4 additions & 0 deletions src/parser/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,10 @@
"category": "Error",
"code": 2609
},
"Property '{0}' is missing in the provided JSX attributes.": {
"category": "Error",
"code": 2610
},
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
"category": "Error",
"code": 2649
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5327,6 +5327,7 @@ declare namespace ts {
JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: DiagnosticMessage;
The_global_type_JSX_0_may_not_have_more_than_one_property: DiagnosticMessage;
JSX_spread_child_must_be_an_array_type: DiagnosticMessage;
Property_0_is_missing_in_the_provided_JSX_attributes: DiagnosticMessage;
Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity: DiagnosticMessage;
A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: DiagnosticMessage;
Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: DiagnosticMessage;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5327,6 +5327,7 @@ declare namespace ts {
JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: DiagnosticMessage;
The_global_type_JSX_0_may_not_have_more_than_one_property: DiagnosticMessage;
JSX_spread_child_must_be_an_array_type: DiagnosticMessage;
Property_0_is_missing_in_the_provided_JSX_attributes: DiagnosticMessage;
Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity: DiagnosticMessage;
A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: DiagnosticMessage;
Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: DiagnosticMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(14,10): error TS2322: Type '{ a: number; b: string; }' is not assignable to type 'Prop'.
Property 'children' is missing in type '{ a: number; b: string; }'.
Property 'children' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(17,11): error TS2710: 'children' are specified twice. The attribute named 'children' will be overwritten.
tests/cases/conformance/jsx/file.tsx(31,6): error TS2322: Type '{ children: (Element | ((name: string) => Element))[]; a: number; b: string; }' is not assignable to type 'Prop'.
Types of property 'children' are incompatible.
Expand Down Expand Up @@ -40,7 +40,7 @@ tests/cases/conformance/jsx/file.tsx(49,6): error TS2322: Type '{ children: Elem
let k = <Comp a={10} b="hi" />;
~~~~
!!! error TS2322: Type '{ a: number; b: string; }' is not assignable to type 'Prop'.
!!! error TS2322: Property 'children' is missing in type '{ a: number; b: string; }'.
!!! error TS2322: Property 'children' is missing in the provided JSX attributes.

let k0 =
<Comp a={10} b="hi" children="Random" >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(20,10): error TS2322: Type '{ a: number; b: string; }' is not assignable to type 'Prop'.
Property 'children' is missing in type '{ a: number; b: string; }'.
Property 'children' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(24,6): error TS2322: Type '{ children: Element; a: number; b: string; }' is not assignable to type 'Prop'.
Types of property 'children' are incompatible.
Type 'Element' is not assignable to type 'Button'.
Expand Down Expand Up @@ -33,7 +33,7 @@ tests/cases/conformance/jsx/file.tsx(28,6): error TS2322: Type '{ children: type
let k = <Comp a={10} b="hi" />;
~~~~
!!! error TS2322: Type '{ a: number; b: string; }' is not assignable to type 'Prop'.
!!! error TS2322: Property 'children' is missing in type '{ a: number; b: string; }'.
!!! error TS2322: Property 'children' is missing in the provided JSX attributes.

// Error: JSX.element is not the same as JSX.ElementClass
let k1 =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(27,13): error TS2322: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'LinkProps'.
Property 'goTo' is missing in type '{ extra: true; onClick: (k: "left" | "right") => void; }'.
Property 'goTo' is missing in the provided JSX attributes.
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(28,13): error TS2322: Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'LinkProps'.
Property 'goTo' is missing in type '{ onClick: (k: "left" | "right") => void; extra: true; }'.
Property 'goTo' is missing in the provided JSX attributes.
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(29,43): error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(30,36): error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(33,65): error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & ButtonProps'.
Expand Down Expand Up @@ -38,11 +38,11 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(36,44): err
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type "left" | "right"
~~~~~~~~~~
!!! error TS2322: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'LinkProps'.
!!! error TS2322: Property 'goTo' is missing in type '{ extra: true; onClick: (k: "left" | "right") => void; }'.
!!! error TS2322: Property 'goTo' is missing in the provided JSX attributes.
const b2 = <MainButton onClick={(k)=>{console.log(k)}} extra />; // k has type "left" | "right"
~~~~~~~~~~
!!! error TS2322: Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'LinkProps'.
!!! error TS2322: Property 'goTo' is missing in type '{ onClick: (k: "left" | "right") => void; extra: true; }'.
!!! error TS2322: Property 'goTo' is missing in the provided JSX attributes.
const b3 = <MainButton {...{goTo:"home"}} extra />; // goTo has type"home" | "contact"
~~~~~
!!! error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxAttributeResolution1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/conformance/jsx/file.tsx(26,8): error TS2326: Types of property 'x'
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/jsx/file.tsx(27,2): error TS2559: Type '{ var: string; }' has no properties in common with type 'Attribs1'.
tests/cases/conformance/jsx/file.tsx(29,2): error TS2322: Type '{}' is not assignable to type '{ reqd: string; }'.
Property 'reqd' is missing in type '{}'.
Property 'reqd' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(30,8): error TS2326: Types of property 'reqd' are incompatible.
Type 'number' is not assignable to type 'string'.

Expand Down Expand Up @@ -55,7 +55,7 @@ tests/cases/conformance/jsx/file.tsx(30,8): error TS2326: Types of property 'req
<test2 />; // Error, missing reqd
~~~~~
!!! error TS2322: Type '{}' is not assignable to type '{ reqd: string; }'.
!!! error TS2322: Property 'reqd' is missing in type '{}'.
!!! error TS2322: Property 'reqd' is missing in the provided JSX attributes.
<test2 reqd={10} />; // Error, reqd is not string
~~~~~~~~~
!!! error TS2326: Types of property 'reqd' are incompatible.
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/tsxAttributeResolution12.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/conformance/jsx/file.tsx(25,11): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { reqd: any; }'.
Type '{}' is not assignable to type '{ reqd: any; }'.
Property 'reqd' is missing in type '{}'.
Property 'reqd' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(28,11): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { reqd: any; }'.
Type '{}' is not assignable to type '{ reqd: any; }'.
Property 'reqd' is missing in type '{}'.
Property 'reqd' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
Expand Down Expand Up @@ -48,13 +48,13 @@ tests/cases/conformance/jsx/file.tsx(28,11): error TS2322: Type '{}' is not assi
~
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { reqd: any; }'.
!!! error TS2322: Type '{}' is not assignable to type '{ reqd: any; }'.
!!! error TS2322: Property 'reqd' is missing in type '{}'.
!!! error TS2322: Property 'reqd' is missing in the provided JSX attributes.

// Should error
var t2 = <TestMod.Test />;
~~~~~~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { reqd: any; }'.
!!! error TS2322: Type '{}' is not assignable to type '{ reqd: any; }'.
!!! error TS2322: Property 'reqd' is missing in type '{}'.
!!! error TS2322: Property 'reqd' is missing in the provided JSX attributes.


4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxAttributeResolution3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests/cases/conformance/jsx/file.tsx(19,2): error TS2322: Type '{ x: number; }'
Types of property 'x' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/jsx/file.tsx(23,2): error TS2322: Type '{ y: number; }' is not assignable to type 'Attribs1'.
Property 'x' is missing in type '{ y: number; }'.
Property 'x' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(31,8): error TS2326: Types of property 'x' are incompatible.
Type 'number' is not assignable to type 'string'.

Expand Down Expand Up @@ -37,7 +37,7 @@ tests/cases/conformance/jsx/file.tsx(31,8): error TS2326: Types of property 'x'
<test1 {...obj3} />
~~~~~
!!! error TS2322: Type '{ y: number; }' is not assignable to type 'Attribs1'.
!!! error TS2322: Property 'x' is missing in type '{ y: number; }'.
!!! error TS2322: Property 'x' is missing in the provided JSX attributes.

// OK
var obj4 = { x: 32, y: 32 };
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxAttributeResolution5.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/conformance/jsx/file.tsx(25,10): error TS2322: Type 'T' is not assig
Type '{ y: string; }' is not assignable to type 'Attribs1'.
Property 'x' is missing in type '{ y: string; }'.
tests/cases/conformance/jsx/file.tsx(29,2): error TS2322: Type '{}' is not assignable to type 'Attribs1'.
Property 'x' is missing in type '{}'.
Property 'x' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
Expand Down Expand Up @@ -50,6 +50,6 @@ tests/cases/conformance/jsx/file.tsx(29,2): error TS2322: Type '{}' is not assig
<test1 {...{}} />; // Error, missing x
~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'Attribs1'.
!!! error TS2322: Property 'x' is missing in type '{}'.
!!! error TS2322: Property 'x' is missing in the provided JSX attributes.
<test2 {...{}} />; // Error, missing toString

4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxAttributeResolution6.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tests/cases/conformance/jsx/file.tsx(10,8): error TS2326: Types of property 's'
tests/cases/conformance/jsx/file.tsx(11,8): error TS2326: Types of property 'n' are incompatible.
Type 'string' is not assignable to type 'boolean'.
tests/cases/conformance/jsx/file.tsx(12,2): error TS2322: Type '{}' is not assignable to type '{ n: boolean; }'.
Property 'n' is missing in type '{}'.
Property 'n' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
Expand All @@ -27,7 +27,7 @@ tests/cases/conformance/jsx/file.tsx(12,2): error TS2322: Type '{}' is not assig
<test2 />;
~~~~~
!!! error TS2322: Type '{}' is not assignable to type '{ n: boolean; }'.
!!! error TS2322: Property 'n' is missing in type '{}'.
!!! error TS2322: Property 'n' is missing in the provided JSX attributes.

// OK
<test1 n />;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxElementResolution3.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(12,2): error TS2322: Type '{ w: string; }' is not assignable to type '{ n: string; }'.
Property 'n' is missing in type '{ w: string; }'.
Property 'n' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
Expand All @@ -17,4 +17,4 @@ tests/cases/conformance/jsx/file.tsx(12,2): error TS2322: Type '{ w: string; }'
<span w='err' />;
~~~~
!!! error TS2322: Type '{ w: string; }' is not assignable to type '{ n: string; }'.
!!! error TS2322: Property 'n' is missing in type '{ w: string; }'.
!!! error TS2322: Property 'n' is missing in the provided JSX attributes.
4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxElementResolution4.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(16,2): error TS2322: Type '{ q: string; }' is not assignable to type '{ m: string; }'.
Property 'm' is missing in type '{ q: string; }'.
Property 'm' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
Expand All @@ -21,5 +21,5 @@ tests/cases/conformance/jsx/file.tsx(16,2): error TS2322: Type '{ q: string; }'
<span q='' />;
~~~~
!!! error TS2322: Type '{ q: string; }' is not assignable to type '{ m: string; }'.
!!! error TS2322: Property 'm' is missing in type '{ q: string; }'.
!!! error TS2322: Property 'm' is missing in the provided JSX attributes.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/tsxIntrinsicAttributeErrors.tsx(29,2): error TS2322: Type '{ x: number; }' is not assignable to type 'IntrinsicAttributes'.
Property 'key' is missing in type '{ x: number; }'.
Property 'key' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/tsxIntrinsicAttributeErrors.tsx (1 errors) ====
Expand Down Expand Up @@ -34,5 +34,5 @@ tests/cases/conformance/jsx/tsxIntrinsicAttributeErrors.tsx(29,2): error TS2322:
<E x={10} />
~
!!! error TS2322: Type '{ x: number; }' is not assignable to type 'IntrinsicAttributes'.
!!! error TS2322: Property 'key' is missing in type '{ x: number; }'.
!!! error TS2322: Property 'key' is missing in the provided JSX attributes.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(13,11): error TS2322: Type '{}' is not assignable to type 'Prop'.
Property 'a' is missing in type '{}'.
Property 'a' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(19,18): error TS2326: Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'number'.

Expand All @@ -20,7 +20,7 @@ tests/cases/conformance/jsx/file.tsx(19,18): error TS2326: Types of property 'a'
let x1 = <MyComp />
~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'Prop'.
!!! error TS2322: Property 'a' is missing in type '{}'.
!!! error TS2322: Property 'a' is missing in the provided JSX attributes.

// OK
let x = <MyComp a={10} b="hi" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsx/file.tsx(11,10): error TS2322: Type '{ property1: string; property2: number; }' is not assignable to type 'AnotherComponentProps'.
Property 'AnotherProperty1' is missing in type '{ property1: string; property2: number; }'.
Property 'AnotherProperty1' is missing in the provided JSX attributes.


==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
Expand All @@ -16,7 +16,7 @@ tests/cases/conformance/jsx/file.tsx(11,10): error TS2322: Type '{ property1: st
<AnotherComponent {...props} />
~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ property1: string; property2: number; }' is not assignable to type 'AnotherComponentProps'.
!!! error TS2322: Property 'AnotherProperty1' is missing in type '{ property1: string; property2: number; }'.
!!! error TS2322: Property 'AnotherProperty1' is missing in the provided JSX attributes.
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/conformance/jsx/file.tsx(17,10): error TS2322: Type '{}' is not assignable to type 'PoisonedProp'.
Property 'x' is missing in type '{}'.
Property 'x' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(18,10): error TS2322: Type '{}' is not assignable to type 'PoisonedProp'.
Property 'x' is missing in type '{}'.
Property 'x' is missing in the provided JSX attributes.
tests/cases/conformance/jsx/file.tsx(19,19): error TS2326: Types of property 'x' are incompatible.
Type 'true' is not assignable to type 'string'.
tests/cases/conformance/jsx/file.tsx(19,21): error TS2326: Types of property 'y' are incompatible.
Expand Down Expand Up @@ -34,11 +34,11 @@ tests/cases/conformance/jsx/file.tsx(21,11): error TS2322: Type '{ X: string; x:
let p = <Poisoned {...obj} />;
~~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'PoisonedProp'.
!!! error TS2322: Property 'x' is missing in type '{}'.
!!! error TS2322: Property 'x' is missing in the provided JSX attributes.
let y = <Poisoned />;
~~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'PoisonedProp'.
!!! error TS2322: Property 'x' is missing in type '{}'.
!!! error TS2322: Property 'x' is missing in the provided JSX attributes.
let z = <Poisoned x y/>;
~
!!! error TS2326: Types of property 'x' are incompatible.
Expand Down
Loading