mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
56 lines
1.9 KiB
Plaintext
56 lines
1.9 KiB
Plaintext
destructuringControlFlow.ts(31,8): error TS2339: Property 'x' does not exist on type 'Number'.
|
|
destructuringControlFlow.ts(32,9): error TS2339: Property 'x' does not exist on type 'Number'.
|
|
destructuringControlFlow.ts(33,9): error TS2537: Type 'Number' has no matching index signature for type 'string'.
|
|
destructuringControlFlow.ts(40,1): error TS18048: 'value' is possibly 'undefined'.
|
|
|
|
|
|
==== destructuringControlFlow.ts (4 errors) ====
|
|
function f1(obj: { a?: string }) {
|
|
if (obj.a) {
|
|
obj = {};
|
|
let a1 = obj["a"]; // string | undefined
|
|
let a2 = obj.a; // string | undefined
|
|
}
|
|
}
|
|
|
|
function f2(obj: [number, string] | null[]) {
|
|
let a0 = obj[0]; // number | null
|
|
let a1 = obj[1]; // string | null
|
|
let [b0, b1] = obj;
|
|
([a0, a1] = obj);
|
|
if (obj[0] && obj[1]) {
|
|
let c0 = obj[0]; // number
|
|
let c1 = obj[1]; // string
|
|
let [d0, d1] = obj;
|
|
([c0, c1] = obj);
|
|
}
|
|
}
|
|
|
|
function f3(obj: { a?: number, b?: string }) {
|
|
if (obj.a && obj.b) {
|
|
let { a, b } = obj; // number, string
|
|
({ a, b } = obj);
|
|
}
|
|
}
|
|
|
|
function f4() {
|
|
let x: boolean;
|
|
({ x } = 0); // Error
|
|
~
|
|
!!! error TS2339: Property 'x' does not exist on type 'Number'.
|
|
({ ["x"]: x } = 0); // Error
|
|
~~~
|
|
!!! error TS2339: Property 'x' does not exist on type 'Number'.
|
|
({ ["x" + ""]: x } = 0); // Errpr
|
|
~~~~~~~~
|
|
!!! error TS2537: Type 'Number' has no matching index signature for type 'string'.
|
|
}
|
|
|
|
// Repro from #31770
|
|
|
|
type KeyValue = [string, string?];
|
|
let [key, value]: KeyValue = ["foo"];
|
|
value.toUpperCase(); // Error
|
|
~~~~~
|
|
!!! error TS18048: 'value' is possibly 'undefined'.
|
|
|