Skip to content

Commit 66b0b44

Browse files
author
Yui T
committed
Address PR
1 parent e8741d8 commit 66b0b44

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13872,11 +13872,11 @@ namespace ts {
1387213872
error(openingLikeElement, Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, getJsxElementPropertiesName());
1387313873
}
1387413874
else {
13875-
checkTypeAssignableTo(sourceAttributesType, targetAttributesType, openingLikeElement.attributes.properties.length > 0 ? openingLikeElement.attributes : openingLikeElement);
13875+
const isSourceAttributeTypeAssignableToTarget = checkTypeAssignableTo(sourceAttributesType, targetAttributesType, openingLikeElement.attributes.properties.length > 0 ? openingLikeElement.attributes : openingLikeElement);
1387613876
// If sourceAttributesType has spread (e.g the type doesn't have freshness flag) after we check for assignability, we will do another pass to check that
1387713877
// all explicitly specified attributes have correct name corresponding with target (as those will be assignable as spread type allows excess properties)
1387813878
// Note: if the type of these explicitly specified attributes do not match it will be an error during above assignability check.
13879-
if (sourceAttributesType !== anyType && !(sourceAttributesType.flags & TypeFlags.FreshLiteral)) {
13879+
if (isSourceAttributeTypeAssignableToTarget && sourceAttributesType !== anyType && !(sourceAttributesType.flags & TypeFlags.FreshLiteral)) {
1388013880
for (const attribute of openingLikeElement.attributes.properties) {
1388113881
if (isJsxAttribute(attribute) && !getPropertyOfType(targetAttributesType, attribute.name.text)) {
1388213882
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, attribute.name.text, typeToString(targetAttributesType));

tests/baselines/reference/contextuallyTypedStringLiteralsInJsxAttributes02.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(27,24): error TS2322: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
22
Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'LinkProps'.
33
Property 'goTo' is missing in type '{ extra: true; onClick: (k: "left" | "right") => void; }'.
4-
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(27,64): error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
54
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(28,24): error TS2322: Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
65
Property 'onClick' does not exist on type 'IntrinsicAttributes & LinkProps'.
76
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(29,43): error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
@@ -11,7 +10,7 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(33,65): err
1110
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(36,44): error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
1211

1312

14-
==== tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx (7 errors) ====
13+
==== tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx (6 errors) ====
1514
import React = require('react')
1615

1716
export interface ClickableProps {
@@ -43,8 +42,6 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(36,44): err
4342
!!! error TS2322: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
4443
!!! error TS2322: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'LinkProps'.
4544
!!! error TS2322: Property 'goTo' is missing in type '{ extra: true; onClick: (k: "left" | "right") => void; }'.
46-
~~~~~
47-
!!! error TS2339: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
4845
const b2 = <MainButton onClick={(k)=>{console.log(k)}} extra />; // k has type "left" | "right"
4946
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5047
!!! error TS2322: Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.

tests/baselines/reference/tsxSpreadAttributesResolution2.errors.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ tests/cases/conformance/jsx/file.tsx(21,20): error TS2322: Type '{ X: "hi"; x: n
1616
Type '{ X: "hi"; x: number; y: "2"; }' is not assignable to type 'PoisonedProp'.
1717
Types of property 'x' are incompatible.
1818
Type 'number' is not assignable to type 'string'.
19-
tests/cases/conformance/jsx/file.tsx(21,40): error TS2339: Property 'X' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Poisoned> & PoisonedProp & { children?: ReactNode; }'.
2019

2120

22-
==== tests/cases/conformance/jsx/file.tsx (6 errors) ====
21+
==== tests/cases/conformance/jsx/file.tsx (5 errors) ====
2322
import React = require('react');
2423

2524
interface PoisonedProp {
@@ -63,6 +62,4 @@ tests/cases/conformance/jsx/file.tsx(21,40): error TS2339: Property 'X' does not
6362
!!! error TS2322: Type '{ X: "hi"; x: number; y: "2"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Poisoned> & PoisonedProp & { children?: ReactNode; }'.
6463
!!! error TS2322: Type '{ X: "hi"; x: number; y: "2"; }' is not assignable to type 'PoisonedProp'.
6564
!!! error TS2322: Types of property 'x' are incompatible.
66-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
67-
~~~~~~
68-
!!! error TS2339: Property 'X' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Poisoned> & PoisonedProp & { children?: ReactNode; }'.
65+
!!! error TS2322: Type 'number' is not assignable to type 'string'.

tests/baselines/reference/tsxStatelessFunctionComponentOverload5.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
tests/cases/conformance/jsx/file.tsx(48,24): error TS2322: Type '{ to: "/some/path"; onClick: (e: MouseEvent<any>) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
22
Property 'to' does not exist on type 'IntrinsicAttributes & HyphenProps'.
3-
tests/cases/conformance/jsx/file.tsx(49,24): error TS2339: Property 'onClick' does not exist on type 'IntrinsicAttributes & HyphenProps'.
43
tests/cases/conformance/jsx/file.tsx(49,24): error TS2322: Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
54
Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'HyphenProps'.
65
Property '"data-format"' is missing in type '{ to: string; onClick: (e: any) => void; children: string; }'.
@@ -25,7 +24,7 @@ tests/cases/conformance/jsx/file.tsx(56,24): error TS2322: Type '{ data-format:
2524
Type 'true' is not assignable to type 'string'.
2625

2726

28-
==== tests/cases/conformance/jsx/file.tsx (9 errors) ====
27+
==== tests/cases/conformance/jsx/file.tsx (8 errors) ====
2928
import React = require('react')
3029

3130
export interface ClickableProps {
@@ -78,8 +77,6 @@ tests/cases/conformance/jsx/file.tsx(56,24): error TS2322: Type '{ data-format:
7877
!!! error TS2322: Type '{ to: "/some/path"; onClick: (e: MouseEvent<any>) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
7978
!!! error TS2322: Property 'to' does not exist on type 'IntrinsicAttributes & HyphenProps'.
8079
const b1 = <MainButton onClick={(e: any)=> {}} {...obj0}>Hello world</MainButton>; // extra property;
81-
~~~~~~~~~~~~~~~~~~~~~~~
82-
!!! error TS2339: Property 'onClick' does not exist on type 'IntrinsicAttributes & HyphenProps'.
8380
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8481
!!! error TS2322: Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
8582
!!! error TS2322: Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'HyphenProps'.

0 commit comments

Comments
 (0)