Skip to content

Commit 1ebbaa1

Browse files
committed
Fix #19775 a bit more
1 parent c51c496 commit 1ebbaa1

7 files changed

+127
-38
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11540,7 +11540,7 @@ namespace ts {
1154011540
return hasExcessProperties(source, discriminant, /*discriminant*/ undefined, reportErrors);
1154111541
}
1154211542
for (const prop of getPropertiesOfObjectType(source)) {
11543-
if (!isPropertyFromSpread(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
11543+
if (shouldCheckAsExcessProp(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
1154411544
if (reportErrors) {
1154511545
// We know *exactly* where things went wrong when comparing the types.
1154611546
// Use this property as the error node as this will be more helpful in
@@ -11585,8 +11585,8 @@ namespace ts {
1158511585
return false;
1158611586
}
1158711587

11588-
function isPropertyFromSpread(prop: Symbol, container: Symbol) {
11589-
return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent !== container.valueDeclaration;
11588+
function shouldCheckAsExcessProp(prop: Symbol, container: Symbol) {
11589+
return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
1159011590
}
1159111591

1159211592
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {

tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//// [tsxSpreadDoesNotReportExcessProps.tsx]
2+
/// <reference path="/.lib/react16.d.ts" />
3+
4+
import React from "react";
5+
6+
class MyComponent extends React.Component<{dataSource: number[], onClick?: any}, {}> {
7+
render() {
8+
return (<div {...this.props} className="ok"></div>);
9+
}
10+
}
11+
12+
13+
//// [tsxSpreadDoesNotReportExcessProps.js]
14+
"use strict";
15+
/// <reference path="react16.d.ts" />
16+
var __extends = (this && this.__extends) || (function () {
17+
var extendStatics = function (d, b) {
18+
extendStatics = Object.setPrototypeOf ||
19+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
20+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
21+
return extendStatics(d, b);
22+
};
23+
return function (d, b) {
24+
extendStatics(d, b);
25+
function __() { this.constructor = d; }
26+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
27+
};
28+
})();
29+
var __assign = (this && this.__assign) || function () {
30+
__assign = Object.assign || function(t) {
31+
for (var s, i = 1, n = arguments.length; i < n; i++) {
32+
s = arguments[i];
33+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
34+
t[p] = s[p];
35+
}
36+
return t;
37+
};
38+
return __assign.apply(this, arguments);
39+
};
40+
var __importDefault = (this && this.__importDefault) || function (mod) {
41+
return (mod && mod.__esModule) ? mod : { "default": mod };
42+
};
43+
exports.__esModule = true;
44+
var react_1 = __importDefault(require("react"));
45+
var MyComponent = /** @class */ (function (_super) {
46+
__extends(MyComponent, _super);
47+
function MyComponent() {
48+
return _super !== null && _super.apply(this, arguments) || this;
49+
}
50+
MyComponent.prototype.render = function () {
51+
return (react_1["default"].createElement("div", __assign({}, this.props, { className: "ok" })));
52+
};
53+
return MyComponent;
54+
}(react_1["default"].Component));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/tsxSpreadDoesNotReportExcessProps.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
4+
import React from "react";
5+
>React : Symbol(React, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 2, 6))
6+
7+
class MyComponent extends React.Component<{dataSource: number[], onClick?: any}, {}> {
8+
>MyComponent : Symbol(MyComponent, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 2, 26))
9+
>React.Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94))
10+
>React : Symbol(React, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 2, 6))
11+
>Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94))
12+
>dataSource : Symbol(dataSource, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 4, 43))
13+
>onClick : Symbol(onClick, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 4, 64))
14+
15+
render() {
16+
>render : Symbol(MyComponent.render, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 4, 86))
17+
18+
return (<div {...this.props} className="ok"></div>);
19+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114))
20+
>this.props : Symbol(React.Component.props, Decl(react16.d.ts, 367, 32))
21+
>this : Symbol(MyComponent, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 2, 26))
22+
>props : Symbol(React.Component.props, Decl(react16.d.ts, 367, 32))
23+
>className : Symbol(className, Decl(tsxSpreadDoesNotReportExcessProps.tsx, 6, 36))
24+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114))
25+
}
26+
}
27+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/tsxSpreadDoesNotReportExcessProps.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
4+
import React from "react";
5+
>React : typeof React
6+
7+
class MyComponent extends React.Component<{dataSource: number[], onClick?: any}, {}> {
8+
>MyComponent : MyComponent
9+
>React.Component : React.Component<{ dataSource: number[]; onClick?: any; }, {}, any>
10+
>React : typeof React
11+
>Component : typeof React.Component
12+
>dataSource : number[]
13+
>onClick : any
14+
15+
render() {
16+
>render : () => JSX.Element
17+
18+
return (<div {...this.props} className="ok"></div>);
19+
>(<div {...this.props} className="ok"></div>) : JSX.Element
20+
><div {...this.props} className="ok"></div> : JSX.Element
21+
>div : any
22+
>this.props : Readonly<{ children?: React.ReactNode; }> & Readonly<{ dataSource: number[]; onClick?: any; }>
23+
>this : this
24+
>props : Readonly<{ children?: React.ReactNode; }> & Readonly<{ dataSource: number[]; onClick?: any; }>
25+
>className : string
26+
>div : any
27+
}
28+
}
29+

tests/baselines/reference/tsxStatelessFunctionComponentOverload4.errors.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ tests/cases/conformance/jsx/file.tsx(26,40): error TS2322: Type 'string' is not
1616
tests/cases/conformance/jsx/file.tsx(33,32): error TS2322: Type 'string' is not assignable to type 'boolean'.
1717
tests/cases/conformance/jsx/file.tsx(34,29): error TS2322: Type 'string' is not assignable to type 'boolean'.
1818
tests/cases/conformance/jsx/file.tsx(35,29): error TS2322: Type 'string' is not assignable to type 'boolean'.
19-
tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type 'string' is not assignable to type 'boolean'.
2019

2120

22-
==== tests/cases/conformance/jsx/file.tsx (11 errors) ====
21+
==== tests/cases/conformance/jsx/file.tsx (10 errors) ====
2322
import React = require('react')
2423
declare function OneThing(): JSX.Element;
2524
declare function OneThing(l: {yy: number, yy1: string}): JSX.Element;
@@ -89,7 +88,4 @@ tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type 'string' is not
8988
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
9089
!!! 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; }'
9190
const e4 = <TestingOptional y1="hello" y2={1000}>Hi</TestingOptional>
92-
~~
93-
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
94-
!!! 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; }'
9591

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @esModuleInterop: true
2+
// @skipLibCheck: true
3+
// @jsx: react
4+
// @strict: true
5+
/// <reference path="/.lib/react16.d.ts" />
6+
7+
import React from "react";
8+
9+
class MyComponent extends React.Component<{dataSource: number[], onClick?: any}, {}> {
10+
render() {
11+
return (<div {...this.props} className="ok"></div>);
12+
}
13+
}

0 commit comments

Comments
 (0)