deno.land / x / froebel@v0.23.2 / map.test.ts

نووسراو ببینە
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
import map from "./map.ts";import { assertEquals, assertThrows } from "testing/asserts.ts";
Deno.test("map", () => { { const input = { foo: 1, [Symbol("bar")]: 2 }; const mapped = map(input, (k, v) => [k, v]); type _0 = Expect<typeof mapped, Record<string | symbol, number>>; assertEquals(mapped, input); // @ts-expect-error type _1 = Expect<typeof mapped, Record<string, number>>; // @ts-expect-error type _2 = Expect<typeof mapped, Record<string | symbol, string>>; }
{ const input = new Map<string, string>([["1", "2"], ["3", "4"]]); const mapped: Map<number, number> = map( input, (key, value) => [parseInt(key), parseInt(value)], ); assertEquals(mapped, new Map([[1, 2], [3, 4]])); }
{ const input = ["1", "2", "3"]; const mapped: number[] = map(input, (v) => parseInt(v)); assertEquals(mapped, [1, 2, 3]); }
{ const input = new Set(["1", "2", "3"]); const mapped: Set<number> = map(input, (v) => parseInt(v)); assertEquals(mapped, new Set([1, 2, 3])); }
// @ts-expect-error assertThrows(() => map(null, (k, v) => [k, v]), TypeError);});
type Expect<T, U extends T> = 0;
froebel

Version Info

Tagged at
a year ago