Skip to content

Commit e5bccaf

Browse files
committed
Include unknown in spread prop override check
1 parent c1f676d commit e5bccaf

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23592,7 +23592,7 @@ namespace ts {
2359223592
for (const right of getPropertiesOfType(type)) {
2359323593
const left = props.get(right.escapedName);
2359423594
const rightType = getTypeOfSymbol(right);
23595-
if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.Any) && right.flags & SymbolFlags.Optional)) {
23595+
if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.AnyOrUnknown) && right.flags & SymbolFlags.Optional)) {
2359623596
const diagnostic = error(left.valueDeclaration, Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, unescapeLeadingUnderscores(left.escapedName));
2359723597
addRelatedInfo(diagnostic, createDiagnosticForNode(spread, Diagnostics.This_spread_always_overwrites_this_property));
2359823598
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [jsxPartialSpread.tsx]
2+
/// <reference path="/.lib/react16.d.ts" />
3+
const Select = (p: {value?: unknown}) => <p></p>;
4+
import React from 'react';
5+
6+
export function Repro({ SelectProps = {} }: { SelectProps?: Partial<Parameters<typeof Select>[0]> }) {
7+
return (
8+
<Select value={'test'} {...SelectProps} />
9+
);
10+
}
11+
12+
//// [jsxPartialSpread.jsx]
13+
"use strict";
14+
var __importDefault = (this && this.__importDefault) || function (mod) {
15+
return (mod && mod.__esModule) ? mod : { "default": mod };
16+
};
17+
exports.__esModule = true;
18+
exports.Repro = void 0;
19+
/// <reference path="react16.d.ts" />
20+
var Select = function (p) { return <p></p>; };
21+
var react_1 = __importDefault(require("react"));
22+
function Repro(_a) {
23+
var _b = _a.SelectProps, SelectProps = _b === void 0 ? {} : _b;
24+
return (<Select value={'test'} {...SelectProps}/>);
25+
}
26+
exports.Repro = Repro;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/jsxPartialSpread.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
const Select = (p: {value?: unknown}) => <p></p>;
4+
>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5))
5+
>p : Symbol(p, Decl(jsxPartialSpread.tsx, 1, 16))
6+
>value : Symbol(value, Decl(jsxPartialSpread.tsx, 1, 20))
7+
>p : Symbol(JSX.IntrinsicElements.p, Decl(react16.d.ts, 2467, 102))
8+
>p : Symbol(JSX.IntrinsicElements.p, Decl(react16.d.ts, 2467, 102))
9+
10+
import React from 'react';
11+
>React : Symbol(React, Decl(jsxPartialSpread.tsx, 2, 6))
12+
13+
export function Repro({ SelectProps = {} }: { SelectProps?: Partial<Parameters<typeof Select>[0]> }) {
14+
>Repro : Symbol(Repro, Decl(jsxPartialSpread.tsx, 2, 26))
15+
>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 23))
16+
>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 45))
17+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
18+
>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --))
19+
>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5))
20+
21+
return (
22+
<Select value={'test'} {...SelectProps} />
23+
>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5))
24+
>value : Symbol(value, Decl(jsxPartialSpread.tsx, 6, 15))
25+
>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 23))
26+
27+
);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/jsxPartialSpread.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
const Select = (p: {value?: unknown}) => <p></p>;
4+
>Select : (p: { value?: unknown;}) => JSX.Element
5+
>(p: {value?: unknown}) => <p></p> : (p: { value?: unknown;}) => JSX.Element
6+
>p : { value?: unknown; }
7+
>value : unknown
8+
><p></p> : JSX.Element
9+
>p : { value?: unknown; }
10+
>p : { value?: unknown; }
11+
12+
import React from 'react';
13+
>React : typeof React
14+
15+
export function Repro({ SelectProps = {} }: { SelectProps?: Partial<Parameters<typeof Select>[0]> }) {
16+
>Repro : ({ SelectProps }: { SelectProps?: Partial<Parameters<typeof Select>[0]>;}) => JSX.Element
17+
>SelectProps : Partial<{ value?: unknown; }>
18+
>{} : {}
19+
>SelectProps : Partial<{ value?: unknown; }> | undefined
20+
>Select : (p: { value?: unknown; }) => JSX.Element
21+
22+
return (
23+
>( <Select value={'test'} {...SelectProps} /> ) : JSX.Element
24+
25+
<Select value={'test'} {...SelectProps} />
26+
><Select value={'test'} {...SelectProps} /> : JSX.Element
27+
>Select : (p: { value?: unknown; }) => JSX.Element
28+
>value : string
29+
>'test' : "test"
30+
>SelectProps : Partial<{ value?: unknown; }>
31+
32+
);
33+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @jsx: preserve
2+
// @esModuleInterop: true
3+
// @strict: true
4+
/// <reference path="/.lib/react16.d.ts" />
5+
const Select = (p: {value?: unknown}) => <p></p>;
6+
import React from 'react';
7+
8+
export function Repro({ SelectProps = {} }: { SelectProps?: Partial<Parameters<typeof Select>[0]> }) {
9+
return (
10+
<Select value={'test'} {...SelectProps} />
11+
);
12+
}

0 commit comments

Comments
 (0)