1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(6,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(16,7): 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(21,7): 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(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(52,24): error TS2322: Type 'null' is not assignable to type 'number'.
==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ====
// https://github.com/Microsoft/TypeScript/issues/17080
declare function f(a:number,b:number): void;
function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) {
f(a, b)
~
!!! 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'.
// error
}
function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) {
f(a, b)
// no error
}
function func3( {a, b}: {a: number, b?: number} = {a: 1} ) {
f(a,b)
~
!!! 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'.
// error
}
function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) {
f(b,c)
~
!!! 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'.
// error
}
function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) {
f(b, c)
// no error
}
function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) {
f(b, c)
~
!!! 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'.
// error
}
function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) {
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'.
}
declare function useBar(bar: number): void;
performFoo();
function performFoo2({ bar = null }: Foo = {}) {
~~~
!!! error TS2322: Type 'null' is not assignable to type 'number'.
useBar2(bar);
}
declare function useBar2(bar: number | undefined): void;
performFoo2();
|