mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-05 00:32:41 -05:00
Fixes #17080
https://github.com/Microsoft/TypeScript/issues/17080 Added testcases from the Github bugreport (all working as intended now). Signed CLA.
This commit is contained in:
@@ -6,7 +6,7 @@ Here's a checklist you might find useful.
|
||||
'Bug' or 'help wanted' or is in the Community milestone
|
||||
[X] Code is up-to-date with the `master` branch
|
||||
[X] You've successfully run `jake runtests` locally
|
||||
[ ] You've signed the CLA
|
||||
[X] You've signed the CLA
|
||||
[X] There are new or updated unit tests validating the change
|
||||
|
||||
Refer to CONTRIBUTING.MD for more details.
|
||||
|
||||
@@ -6,9 +6,13 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(21,7): e
|
||||
Type 'undefined' is not assignable to type 'number'.
|
||||
tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
|
||||
Type 'undefined' is not assignable to type 'number'.
|
||||
tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(45,10): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
|
||||
Type 'undefined' is not assignable to type 'number'.
|
||||
tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'.
|
||||
Type 'null' is not assignable to type 'number | undefined'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (4 errors) ====
|
||||
==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ====
|
||||
// https://github.com/Microsoft/TypeScript/issues/17080
|
||||
function f(a:number,b:number) {
|
||||
}
|
||||
@@ -59,4 +63,36 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): e
|
||||
f(b, c)
|
||||
// no error
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
readonly bar?: number;
|
||||
}
|
||||
|
||||
function performFoo({ bar }: Foo = {}) {
|
||||
useBar(bar);
|
||||
~~~
|
||||
!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
|
||||
!!! error TS2345: Type 'undefined' is not assignable to type 'number'.
|
||||
}
|
||||
|
||||
function useBar(bar: number) {
|
||||
f(bar, 1)
|
||||
}
|
||||
|
||||
performFoo();
|
||||
|
||||
function performFoo2({ bar = null }: Foo = {}) {
|
||||
useBar2(bar);
|
||||
~~~
|
||||
!!! error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'.
|
||||
!!! error TS2345: Type 'null' is not assignable to type 'number | undefined'.
|
||||
}
|
||||
|
||||
function useBar2(bar: number | undefined) {
|
||||
if (bar) {
|
||||
f(bar, 1)
|
||||
}
|
||||
}
|
||||
|
||||
performFoo2();
|
||||
|
||||
@@ -37,6 +37,32 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number},
|
||||
f(b, c)
|
||||
// no error
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
readonly bar?: number;
|
||||
}
|
||||
|
||||
function performFoo({ bar }: Foo = {}) {
|
||||
useBar(bar);
|
||||
}
|
||||
|
||||
function useBar(bar: number) {
|
||||
f(bar, 1)
|
||||
}
|
||||
|
||||
performFoo();
|
||||
|
||||
function performFoo2({ bar = null }: Foo = {}) {
|
||||
useBar2(bar);
|
||||
}
|
||||
|
||||
function useBar2(bar: number | undefined) {
|
||||
if (bar) {
|
||||
f(bar, 1)
|
||||
}
|
||||
}
|
||||
|
||||
performFoo2();
|
||||
|
||||
|
||||
//// [optionalParameterInDestructuringWithInitializer.js]
|
||||
@@ -78,3 +104,21 @@ function func7(_a) {
|
||||
f(b, c);
|
||||
// no error
|
||||
}
|
||||
function performFoo(_a) {
|
||||
var bar = (_a === void 0 ? {} : _a).bar;
|
||||
useBar(bar);
|
||||
}
|
||||
function useBar(bar) {
|
||||
f(bar, 1);
|
||||
}
|
||||
performFoo();
|
||||
function performFoo2(_a) {
|
||||
var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b;
|
||||
useBar2(bar);
|
||||
}
|
||||
function useBar2(bar) {
|
||||
if (bar) {
|
||||
f(bar, 1);
|
||||
}
|
||||
}
|
||||
performFoo2();
|
||||
|
||||
@@ -152,3 +152,58 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number},
|
||||
// no error
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1))
|
||||
|
||||
readonly bar?: number;
|
||||
>bar : Symbol(Foo.bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 39, 15))
|
||||
}
|
||||
|
||||
function performFoo({ bar }: Foo = {}) {
|
||||
>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21))
|
||||
>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1))
|
||||
|
||||
useBar(bar);
|
||||
>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21))
|
||||
}
|
||||
|
||||
function useBar(bar: number) {
|
||||
>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16))
|
||||
|
||||
f(bar, 1)
|
||||
>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16))
|
||||
}
|
||||
|
||||
performFoo();
|
||||
>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1))
|
||||
|
||||
function performFoo2({ bar = null }: Foo = {}) {
|
||||
>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22))
|
||||
>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1))
|
||||
|
||||
useBar2(bar);
|
||||
>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22))
|
||||
}
|
||||
|
||||
function useBar2(bar: number | undefined) {
|
||||
>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17))
|
||||
|
||||
if (bar) {
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17))
|
||||
|
||||
f(bar, 1)
|
||||
>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0))
|
||||
>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17))
|
||||
}
|
||||
}
|
||||
|
||||
performFoo2();
|
||||
>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13))
|
||||
|
||||
|
||||
@@ -196,3 +196,69 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number},
|
||||
// no error
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
>Foo : Foo
|
||||
|
||||
readonly bar?: number;
|
||||
>bar : number | undefined
|
||||
}
|
||||
|
||||
function performFoo({ bar }: Foo = {}) {
|
||||
>performFoo : ({ bar }?: Foo) => void
|
||||
>bar : number | undefined
|
||||
>Foo : Foo
|
||||
>{} : {}
|
||||
|
||||
useBar(bar);
|
||||
>useBar(bar) : void
|
||||
>useBar : (bar: number) => void
|
||||
>bar : number | undefined
|
||||
}
|
||||
|
||||
function useBar(bar: number) {
|
||||
>useBar : (bar: number) => void
|
||||
>bar : number
|
||||
|
||||
f(bar, 1)
|
||||
>f(bar, 1) : void
|
||||
>f : (a: number, b: number) => void
|
||||
>bar : number
|
||||
>1 : 1
|
||||
}
|
||||
|
||||
performFoo();
|
||||
>performFoo() : void
|
||||
>performFoo : ({ bar }?: Foo) => void
|
||||
|
||||
function performFoo2({ bar = null }: Foo = {}) {
|
||||
>performFoo2 : ({ bar }?: Foo) => void
|
||||
>bar : number | null
|
||||
>null : null
|
||||
>Foo : Foo
|
||||
>{} : {}
|
||||
|
||||
useBar2(bar);
|
||||
>useBar2(bar) : void
|
||||
>useBar2 : (bar: number | undefined) => void
|
||||
>bar : number | null
|
||||
}
|
||||
|
||||
function useBar2(bar: number | undefined) {
|
||||
>useBar2 : (bar: number | undefined) => void
|
||||
>bar : number | undefined
|
||||
|
||||
if (bar) {
|
||||
>bar : number | undefined
|
||||
|
||||
f(bar, 1)
|
||||
>f(bar, 1) : void
|
||||
>f : (a: number, b: number) => void
|
||||
>bar : number
|
||||
>1 : 1
|
||||
}
|
||||
}
|
||||
|
||||
performFoo2();
|
||||
>performFoo2() : void
|
||||
>performFoo2 : ({ bar }?: Foo) => void
|
||||
|
||||
|
||||
@@ -37,3 +37,29 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number},
|
||||
f(b, c)
|
||||
// no error
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
readonly bar?: number;
|
||||
}
|
||||
|
||||
function performFoo({ bar }: Foo = {}) {
|
||||
useBar(bar);
|
||||
}
|
||||
|
||||
function useBar(bar: number) {
|
||||
f(bar, 1)
|
||||
}
|
||||
|
||||
performFoo();
|
||||
|
||||
function performFoo2({ bar = null }: Foo = {}) {
|
||||
useBar2(bar);
|
||||
}
|
||||
|
||||
function useBar2(bar: number | undefined) {
|
||||
if (bar) {
|
||||
f(bar, 1)
|
||||
}
|
||||
}
|
||||
|
||||
performFoo2();
|
||||
|
||||
Reference in New Issue
Block a user