mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
58 lines
1.7 KiB
Plaintext
58 lines
1.7 KiB
Plaintext
logicalAssignment4.ts(39,13): error TS18048: 'defaultValue' is possibly 'undefined'.
|
|
logicalAssignment4.ts(45,13): error TS18048: 'defaultValue' is possibly 'undefined'.
|
|
|
|
|
|
==== logicalAssignment4.ts (2 errors) ====
|
|
function foo1(results: number[] | undefined) {
|
|
(results ||= []).push(100);
|
|
}
|
|
|
|
function foo2(results: number[] | undefined) {
|
|
(results ??= []).push(100);
|
|
}
|
|
|
|
function foo3(results: number[] | undefined) {
|
|
results ||= [];
|
|
results.push(100);
|
|
}
|
|
|
|
function foo4(results: number[] | undefined) {
|
|
results ??= [];
|
|
results.push(100);
|
|
}
|
|
|
|
interface ThingWithOriginal {
|
|
name: string;
|
|
original?: ThingWithOriginal
|
|
}
|
|
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;
|
|
~~~~~~~~~~~~
|
|
!!! error TS18048: 'defaultValue' is possibly 'undefined'.
|
|
}
|
|
}
|
|
else {
|
|
if (thing ??= defaultValue) {
|
|
thing.name;
|
|
defaultValue.name;
|
|
~~~~~~~~~~~~
|
|
!!! error TS18048: 'defaultValue' is possibly 'undefined'.
|
|
}
|
|
}
|
|
}
|
|
|