mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
//// [tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts] ////
|
|
|
|
//// [destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts]
|
|
// To be inferred as `number`
|
|
function f1() {
|
|
const { a1, b1 = a1 } = { a1: 1 };
|
|
const { a2, b2 = 1 + a2 } = { a2: 1 };
|
|
}
|
|
|
|
// To be inferred as `string`
|
|
function f2() {
|
|
const { a1, b1 = a1 } = { a1: 'hi' };
|
|
const { a2, b2 = a2 + '!' } = { a2: 'hi' };
|
|
}
|
|
|
|
// To be inferred as `string | number`
|
|
function f3() {
|
|
const { a1, b1 = a1 } = { a1: 'hi', b1: 1 };
|
|
const { a2, b2 = a2 + '!' } = { a2: 'hi', b2: 1 };
|
|
}
|
|
|
|
// Based on comment:
|
|
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
|
|
declare const yadda: { a?: number, b?: number } | undefined
|
|
function f4() {
|
|
const { a, b = a } = yadda ?? {};
|
|
}
|
|
|
|
|
|
//// [destructuringObjectBindingPatternAndAssignment9SiblingInitializer.js]
|
|
"use strict";
|
|
// To be inferred as `number`
|
|
function f1() {
|
|
const { a1, b1 = a1 } = { a1: 1 };
|
|
const { a2, b2 = 1 + a2 } = { a2: 1 };
|
|
}
|
|
// To be inferred as `string`
|
|
function f2() {
|
|
const { a1, b1 = a1 } = { a1: 'hi' };
|
|
const { a2, b2 = a2 + '!' } = { a2: 'hi' };
|
|
}
|
|
// To be inferred as `string | number`
|
|
function f3() {
|
|
const { a1, b1 = a1 } = { a1: 'hi', b1: 1 };
|
|
const { a2, b2 = a2 + '!' } = { a2: 'hi', b2: 1 };
|
|
}
|
|
function f4() {
|
|
const { a, b = a } = yadda !== null && yadda !== void 0 ? yadda : {};
|
|
}
|