From 8037e26dd4b9d2db926597a6e8d87d4523c5e202 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 14 May 2020 15:29:33 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#38577=20(Include=20?= =?UTF-8?q?unknown=20in=20spread=20prop=20over...)=20into=20release-3.9=20?= =?UTF-8?q?(#38581)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Cherry-pick PR #38577 into release-3.9 Component commits: e5bccafc29 Include unknown in spread prop override check * Empty commit Co-authored-by: Wesley Wigham Co-authored-by: Wesley Wigham --- src/compiler/checker.ts | 2 +- tests/baselines/reference/jsxPartialSpread.js | 26 +++++++++++++++ .../reference/jsxPartialSpread.symbols | 28 ++++++++++++++++ .../reference/jsxPartialSpread.types | 33 +++++++++++++++++++ tests/cases/compiler/jsxPartialSpread.tsx | 12 +++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsxPartialSpread.js create mode 100644 tests/baselines/reference/jsxPartialSpread.symbols create mode 100644 tests/baselines/reference/jsxPartialSpread.types create mode 100644 tests/cases/compiler/jsxPartialSpread.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 21ea8c7347e..e962997ee02 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23529,7 +23529,7 @@ namespace ts { for (const right of getPropertiesOfType(type)) { const left = props.get(right.escapedName); const rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.Any) && right.flags & SymbolFlags.Optional)) { + if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.AnyOrUnknown) && right.flags & SymbolFlags.Optional)) { const diagnostic = error(left.valueDeclaration, Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, unescapeLeadingUnderscores(left.escapedName)); addRelatedInfo(diagnostic, createDiagnosticForNode(spread, Diagnostics.This_spread_always_overwrites_this_property)); } diff --git a/tests/baselines/reference/jsxPartialSpread.js b/tests/baselines/reference/jsxPartialSpread.js new file mode 100644 index 00000000000..e37b12f7d7a --- /dev/null +++ b/tests/baselines/reference/jsxPartialSpread.js @@ -0,0 +1,26 @@ +//// [jsxPartialSpread.tsx] +/// +const Select = (p: {value?: unknown}) =>

; +import React from 'react'; + +export function Repro({ SelectProps = {} }: { SelectProps?: Partial[0]> }) { + return ( + ); +} +exports.Repro = Repro; diff --git a/tests/baselines/reference/jsxPartialSpread.symbols b/tests/baselines/reference/jsxPartialSpread.symbols new file mode 100644 index 00000000000..7b0a1710649 --- /dev/null +++ b/tests/baselines/reference/jsxPartialSpread.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/jsxPartialSpread.tsx === +/// +const Select = (p: {value?: unknown}) =>

; +>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5)) +>p : Symbol(p, Decl(jsxPartialSpread.tsx, 1, 16)) +>value : Symbol(value, Decl(jsxPartialSpread.tsx, 1, 20)) +>p : Symbol(JSX.IntrinsicElements.p, Decl(react16.d.ts, 2467, 102)) +>p : Symbol(JSX.IntrinsicElements.p, Decl(react16.d.ts, 2467, 102)) + +import React from 'react'; +>React : Symbol(React, Decl(jsxPartialSpread.tsx, 2, 6)) + +export function Repro({ SelectProps = {} }: { SelectProps?: Partial[0]> }) { +>Repro : Symbol(Repro, Decl(jsxPartialSpread.tsx, 2, 26)) +>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 23)) +>SelectProps : Symbol(SelectProps, Decl(jsxPartialSpread.tsx, 4, 45)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --)) +>Select : Symbol(Select, Decl(jsxPartialSpread.tsx, 1, 5)) + + return ( + ) : JSX.Element + + : JSX.Element +>Select : (p: { value?: unknown; }) => JSX.Element +>value : string +>'test' : "test" +>SelectProps : Partial<{ value?: unknown; }> + + ); +} diff --git a/tests/cases/compiler/jsxPartialSpread.tsx b/tests/cases/compiler/jsxPartialSpread.tsx new file mode 100644 index 00000000000..b71ee00e5d9 --- /dev/null +++ b/tests/cases/compiler/jsxPartialSpread.tsx @@ -0,0 +1,12 @@ +// @jsx: preserve +// @esModuleInterop: true +// @strict: true +/// +const Select = (p: {value?: unknown}) =>

; +import React from 'react'; + +export function Repro({ SelectProps = {} }: { SelectProps?: Partial[0]> }) { + return ( +