-
Notifications
You must be signed in to change notification settings - Fork 12.2k
/
isArray.errors.txt
69 lines (57 loc) · 3.12 KB
/
isArray.errors.txt
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
61
62
63
64
65
66
67
68
69
tests/cases/compiler/isArray.ts(15,9): error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
tests/cases/compiler/isArray.ts(26,9): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'.
Type 'string' is not assignable to type 'void'.
tests/cases/compiler/isArray.ts(32,9): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'.
tests/cases/compiler/isArray.ts(41,9): error TS2322: Type 'any[]' is not assignable to type 'void'.
tests/cases/compiler/isArray.ts(47,9): error TS2322: Type 'any[]' is not assignable to type 'void'.
==== tests/cases/compiler/isArray.ts (5 errors) ====
/// @errors: 2322 4104
// https://github.com/microsoft/TypeScript/issues/17002
// Preserves mutability, false branch removes arrays, mutable or not
declare const mutable: string | string[];
if (Array.isArray(mutable)) {
const stillMutable: string[] = mutable;
} else {
const narrowed: string = mutable;
}
declare const immutable: string | readonly string[];
if (Array.isArray(immutable)) {
const notMutable: string[] = immutable; // Should fail: readonly string[] isn't assignable to string[]
~~~~~~~~~~
!!! error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
} else {
const narrowed: string = immutable;
}
// https://github.com/microsoft/TypeScript/issues/33700
// Preserves element or iterated type of wider types
declare const arrayLike: string | ArrayLike<string>;
if (Array.isArray(arrayLike)) {
const arrayOfElementType: readonly string[] = arrayLike;
const notArrayOfAny: readonly void[] = arrayLike; // Should fail: string isn't assignable to void
~~~~~~~~~~~~~
!!! error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'.
!!! error TS2322: Type 'string' is not assignable to type 'void'.
}
declare const iterable: string | Iterable<string>;
if (Array.isArray(iterable)) {
const arrayOfIteratedType: readonly string[] = iterable;
const notArrayOfAny: readonly void[] = iterable; // Should fail: string isn't assignable to void
~~~~~~~~~~~~~
!!! error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'.
}
// https://github.com/microsoft/TypeScript/pull/42316#discussion_r823218462
// any and unknown backward compatibility
declare const any: any;
if (Array.isArray(any)) {
const mutableArrayOfAny: void[] = any;
const notAny: void = any; // Should fail: any[] isn't assignable to void
~~~~~~
!!! error TS2322: Type 'any[]' is not assignable to type 'void'.
}
declare const unknown: unknown;
if (Array.isArray(unknown)) {
const mutableArrayOfAny: void[] = unknown;
const notAny: void = unknown; // Should fail: any[] isn't assignable to void
~~~~~~
!!! error TS2322: Type 'any[]' is not assignable to type 'void'.
}