forked from rocicorp/mono
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimmutable.test.ts
More file actions
47 lines (42 loc) · 1.01 KB
/
immutable.test.ts
File metadata and controls
47 lines (42 loc) · 1.01 KB
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
import {expectTypeOf, test} from 'vitest';
import type {Immutable, ImmutableArray} from './immutable.ts';
import type {ReadonlyJSONValue} from './json.ts';
test('type testing immutable', () => {
const x = [
{
a: 1,
b: '2',
c: [1, 2, 3],
},
];
const xi = x as Immutable<typeof x>;
expectTypeOf(xi[0].c).toEqualTypeOf<ImmutableArray<number>>();
});
test('testing with readonly array', () => {
type NumberOrArray = number | ReadonlyArray<NumberOrArray>;
type X = ImmutableArray<NumberOrArray>;
const x: X = [1];
expectTypeOf(x).toEqualTypeOf<ImmutableArray<NumberOrArray>>();
});
test('type from discord', () => {
function f(
flagsUpdate: ImmutableArray<{
readonly userID: string;
readonly value: ReadonlyJSONValue;
}>,
) {
return flagsUpdate;
}
expectTypeOf(f).returns.toEqualTypeOf<
ImmutableArray<{
readonly userID: string;
readonly value: ReadonlyJSONValue;
}>
>();
f([
{
userID: '1',
value: [1],
},
]);
});