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
|
//// [controlFlowParameter.ts]
function f1(
required: unknown = (() => {
throw new Error("bad");
})()
) {
console.log("ok"); // should not trigger 'Unreachable code detected.'
}
function f2(
a: number | string | undefined,
required: unknown = (() => {
a = 1;
})()
) {
a; // should be number | string | undefined
}
function f3(
a: number | string | undefined = 1,
required: unknown = (() => {
a = "";
})()
) {
a; // should be number | string
}
function f4(
a: number | string | undefined = 1,
{ [(a = "")]: b } = {} as any
) {
a; // should be string
}
//// [controlFlowParameter.js]
function f1(required) {
if (required === void 0) { required = (function () {
throw new Error("bad");
})(); }
console.log("ok"); // should not trigger 'Unreachable code detected.'
}
function f2(a, required) {
if (required === void 0) { required = (function () {
a = 1;
})(); }
a; // should be number | string | undefined
}
function f3(a, required) {
if (a === void 0) { a = 1; }
if (required === void 0) { required = (function () {
a = "";
})(); }
a; // should be number | string
}
function f4(a, _a) {
if (a === void 0) { a = 1; }
var _b = _a === void 0 ? {} : _a, _c = (a = ""), b = _b[_c];
a; // should be string
}
|