|
| 1 | +tests/cases/compiler/controlFlowArrayErrors.ts(5,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 2 | +tests/cases/compiler/controlFlowArrayErrors.ts(6,13): error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 3 | +tests/cases/compiler/controlFlowArrayErrors.ts(12,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 4 | +tests/cases/compiler/controlFlowArrayErrors.ts(14,13): error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 5 | +tests/cases/compiler/controlFlowArrayErrors.ts(20,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 6 | +tests/cases/compiler/controlFlowArrayErrors.ts(23,9): error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 7 | +tests/cases/compiler/controlFlowArrayErrors.ts(30,12): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. |
| 8 | +tests/cases/compiler/controlFlowArrayErrors.ts(35,12): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. |
| 9 | +tests/cases/compiler/controlFlowArrayErrors.ts(49,5): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((...items: (string | number)[]) => number) | ((...items: boolean[]) => number)' has no compatible call signatures. |
| 10 | +tests/cases/compiler/controlFlowArrayErrors.ts(57,12): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. |
| 11 | +tests/cases/compiler/controlFlowArrayErrors.ts(61,11): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 12 | +tests/cases/compiler/controlFlowArrayErrors.ts(64,9): error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 13 | + |
| 14 | + |
| 15 | +==== tests/cases/compiler/controlFlowArrayErrors.ts (12 errors) ==== |
| 16 | + |
| 17 | + declare function cond(): boolean; |
| 18 | + |
| 19 | + function f1() { |
| 20 | + let x = []; // Implicit any[] error in some locations |
| 21 | + ~ |
| 22 | +!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 23 | + let y = x; // Implicit any[] error |
| 24 | + ~ |
| 25 | +!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 26 | + x.push(5); |
| 27 | + let z = x; |
| 28 | + } |
| 29 | + |
| 30 | + function f2() { |
| 31 | + let x; // Implicit any[] error in some locations |
| 32 | + ~ |
| 33 | +!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 34 | + x = []; |
| 35 | + let y = x; // Implicit any[] error |
| 36 | + ~ |
| 37 | +!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 38 | + x.push(5); |
| 39 | + let z = x; |
| 40 | + } |
| 41 | + |
| 42 | + function f3() { |
| 43 | + let x = []; // Implicit any[] error in some locations |
| 44 | + ~ |
| 45 | +!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 46 | + x.push(5); |
| 47 | + function g() { |
| 48 | + x; // Implicit any[] error |
| 49 | + ~ |
| 50 | +!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + function f4() { |
| 55 | + let x; |
| 56 | + x = [5, "hello"]; // Non-evolving array |
| 57 | + x.push(true); // Error |
| 58 | + ~~~~ |
| 59 | +!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. |
| 60 | + } |
| 61 | + |
| 62 | + function f5() { |
| 63 | + let x = [5, "hello"]; // Non-evolving array |
| 64 | + x.push(true); // Error |
| 65 | + ~~~~ |
| 66 | +!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. |
| 67 | + } |
| 68 | + |
| 69 | + function f6() { |
| 70 | + let x; |
| 71 | + if (cond()) { |
| 72 | + x = []; |
| 73 | + x.push(5); |
| 74 | + x.push("hello"); |
| 75 | + } |
| 76 | + else { |
| 77 | + x = [true]; // Non-evolving array |
| 78 | + } |
| 79 | + x; // boolean[] | (string | number)[] |
| 80 | + x.push(99); // Error |
| 81 | + ~~~~~~~~~~ |
| 82 | +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((...items: (string | number)[]) => number) | ((...items: boolean[]) => number)' has no compatible call signatures. |
| 83 | + } |
| 84 | + |
| 85 | + function f7() { |
| 86 | + let x = []; // x has evolving array value |
| 87 | + x.push(5); |
| 88 | + let y = x; // y has non-evolving array value |
| 89 | + x.push("hello"); // Ok |
| 90 | + y.push("hello"); // Error |
| 91 | + ~~~~~~~ |
| 92 | +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. |
| 93 | + } |
| 94 | + |
| 95 | + function f8() { |
| 96 | + const x = []; // Implicit any[] error in some locations |
| 97 | + ~ |
| 98 | +!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. |
| 99 | + x.push(5); |
| 100 | + function g() { |
| 101 | + x; // Implicit any[] error |
| 102 | + ~ |
| 103 | +!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. |
| 104 | + } |
| 105 | + } |
0 commit comments