Skip to content

Don't allow properties inherited from Object to be automatically included in TSX attributes #10153

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

Merged
1 commit merged into from
Aug 5, 2016
Merged
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
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10060,7 +10060,7 @@ namespace ts {
for (const prop of props) {
// Is there a corresponding property in the element attributes type? Skip checking of properties
// that have already been assigned to, as these are not actually pushed into the resulting type
if (!nameTable[prop.name]) {
if (!hasProperty(nameTable, prop.name)) {
const targetPropSym = getPropertyOfType(elementAttributesType, prop.name);
if (targetPropSym) {
const msg = chainDiagnosticMessages(undefined, Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name);
Expand Down Expand Up @@ -10406,7 +10406,7 @@ namespace ts {
const targetProperties = getPropertiesOfType(targetAttributesType);
for (let i = 0; i < targetProperties.length; i++) {
if (!(targetProperties[i].flags & SymbolFlags.Optional) &&
nameTable[targetProperties[i].name] === undefined) {
!hasProperty(nameTable, targetProperties[i].name)) {

error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
}
Expand Down
7 changes: 5 additions & 2 deletions tests/baselines/reference/tsxAttributeResolution5.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ tests/cases/conformance/jsx/file.tsx(21,16): error TS2606: Property 'x' of JSX s
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/jsx/file.tsx(25,9): error TS2324: Property 'x' is missing in type 'Attribs1'.
tests/cases/conformance/jsx/file.tsx(29,1): error TS2324: Property 'x' is missing in type 'Attribs1'.
tests/cases/conformance/jsx/file.tsx(30,1): error TS2324: Property 'toString' is missing in type 'Attribs2'.


==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
==== tests/cases/conformance/jsx/file.tsx (4 errors) ====
declare module JSX {
interface Element { }
interface IntrinsicElements {
Expand Down Expand Up @@ -41,5 +42,7 @@ tests/cases/conformance/jsx/file.tsx(29,1): error TS2324: Property 'x' is missin
<test1 {...{}} />; // Error, missing x
~~~~~~~~~~~~~~~~~
!!! error TS2324: Property 'x' is missing in type 'Attribs1'.
<test2 {...{}} />; // OK
<test2 {...{}} />; // Error, missing toString
~~~~~~~~~~~~~~~~~
!!! error TS2324: Property 'toString' is missing in type 'Attribs2'.

4 changes: 2 additions & 2 deletions tests/baselines/reference/tsxAttributeResolution5.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function make3<T extends {y: string}> (obj: T) {


<test1 {...{}} />; // Error, missing x
<test2 {...{}} />; // OK
<test2 {...{}} />; // Error, missing toString


//// [file.jsx]
Expand All @@ -42,4 +42,4 @@ function make3(obj) {
return <test1 {...obj}/>; // Error, missing x
}
<test1 {...{}}/>; // Error, missing x
<test2 {...{}}/>; // OK
<test2 {...{}}/>; // Error, missing toString
2 changes: 1 addition & 1 deletion tests/cases/conformance/jsx/tsxAttributeResolution5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ function make3<T extends {y: string}> (obj: T) {


<test1 {...{}} />; // Error, missing x
<test2 {...{}} />; // OK
<test2 {...{}} />; // Error, missing toString