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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
//// [optionalParameterInDestructuringWithInitializer.ts]
// 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
}
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
}
function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) {
f(b,c)
// 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
}
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);
}
declare function useBar(bar: number): void;
performFoo();
function performFoo2({ bar = null }: Foo = {}) {
useBar2(bar);
}
declare function useBar2(bar: number | undefined): void;
performFoo2();
//// [optionalParameterInDestructuringWithInitializer.js]
// https://github.com/Microsoft/TypeScript/issues/17080
function func1(_a) {
var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, b = _b.b;
f(a, b);
// error
}
function func2(_a) {
var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, _c = _b.b, b = _c === void 0 ? 3 : _c;
f(a, b);
// no error
}
function func3(_a) {
var _b = _a === void 0 ? { a: 1 } : _a, a = _b.a, b = _b.b;
f(a, b);
// error
}
function func4(_a) {
var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, c = _c.c, d = _b.d;
f(b, c);
// error
}
function func5(_a) {
var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, _d = _c.c, c = _d === void 0 ? 4 : _d, d = _b.d;
f(b, c);
// no error
}
function func6(_a) {
var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, c = _d.c, d = _b.d;
f(b, c);
// error
}
function func7(_a) {
var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, _e = _d.c, c = _e === void 0 ? 6 : _e, d = _b.d;
f(b, c);
// no error
}
function performFoo(_a) {
var bar = (_a === void 0 ? {} : _a).bar;
useBar(bar);
}
performFoo();
function performFoo2(_a) {
var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b;
useBar2(bar);
}
performFoo2();
|