2020-04-01 05:37:58 +02:00
|
|
|
// @strict: true
|
2021-03-10 22:31:25 +01:00
|
|
|
// @target: esnext, es2021, es2020, es2015
|
2020-04-01 21:01:19 +02:00
|
|
|
// @allowUnreachableCode: false
|
2020-04-01 05:37:58 +02:00
|
|
|
|
|
|
|
function foo1(results: number[] | undefined) {
|
|
|
|
(results ||= []).push(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo2(results: number[] | undefined) {
|
|
|
|
(results ??= []).push(100);
|
2020-04-01 17:39:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function foo3(results: number[] | undefined) {
|
|
|
|
results ||= [];
|
|
|
|
results.push(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo4(results: number[] | undefined) {
|
2020-04-02 10:29:04 +02:00
|
|
|
results ??= [];
|
2020-04-01 17:39:38 +02:00
|
|
|
results.push(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ThingWithOriginal {
|
|
|
|
name: string;
|
|
|
|
original?: ThingWithOriginal
|
|
|
|
}
|
2020-04-08 06:09:56 +02:00
|
|
|
declare const v: number
|
|
|
|
function doSomethingWithAlias(thing: ThingWithOriginal | undefined, defaultValue: ThingWithOriginal | undefined) {
|
|
|
|
if (v === 1) {
|
|
|
|
if (thing &&= thing.original) {
|
|
|
|
thing.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v === 2) {
|
|
|
|
if (thing &&= defaultValue) {
|
|
|
|
thing.name;
|
|
|
|
defaultValue.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v === 3) {
|
|
|
|
if (thing ||= defaultValue) {
|
|
|
|
thing.name;
|
|
|
|
defaultValue.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (thing ??= defaultValue) {
|
|
|
|
thing.name;
|
|
|
|
defaultValue.name;
|
|
|
|
}
|
2020-04-01 17:39:38 +02:00
|
|
|
}
|
2021-03-10 22:31:25 +01:00
|
|
|
}
|