deno.land / std@0.166.0 / _util / assert_type_test.ts

assert_type_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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// deno-lint-ignore-file no-explicit-any// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Original author: @dsherret https://github.com/dsherret/conditional-type-checks
import { assertType, IsAny, IsExact } from "./assert_type.ts";
// IsExact{ // matching assertType<IsExact<string | number, string | number>>(true); assertType<IsExact<string | number | Date, string | number | Date>>(true); assertType<IsExact<string | undefined, string | undefined>>(true); assertType<IsExact<any, any>>(true); // ok to have any for both assertType<IsExact<unknown, unknown>>(true); assertType<IsExact<never, never>>(true); // deno-lint-ignore ban-types assertType<IsExact<{}, {}>>(true); assertType<IsExact<{ prop: string }, { prop: string }>>(true); assertType<IsExact<{ prop: { prop: string } }, { prop: { prop: string } }>>( true, ); assertType<IsExact<{ prop: never }, { prop: never }>>(true); assertType<IsExact<{ prop: any }, { prop: any }>>(true); assertType<IsExact<{ prop: unknown }, { prop: unknown }>>(true); assertType<IsExact<Window, Window>>(true);
// not matching assertType<IsExact<string | number | Date, string | number>>(false); assertType<IsExact<string, string | number>>(false); assertType<IsExact<string | undefined, string>>(false); assertType<IsExact<string | undefined, any | string>>(false); assertType<IsExact<any | string | undefined, string>>(false); assertType<IsExact<string, any>>(false); assertType<IsExact<string, unknown>>(false); assertType<IsExact<string, never>>(false); assertType<IsExact<never, never | string>>(false); assertType<IsExact<unknown, any>>(false); assertType<IsExact<never, any>>(false); assertType<IsExact<Date | Window, Date>>(false); assertType<IsExact<{ name: string; other?: Date }, { name: string }>>(false); assertType<IsExact<{ prop: Date }, { prop: string }>>(false); assertType<IsExact<{ other?: Date }, { prop?: string }>>(false); assertType<IsExact<{ prop: { prop?: string } }, { prop: { prop: string } }>>( false, ); assertType<IsExact<{ prop: any }, { prop: string }>>(false); assertType<IsExact<{ prop: any }, { prop: unknown }>>(false); assertType<IsExact<{ prop: any }, { prop: never }>>(false); assertType<IsExact<{ prop: unknown }, { prop: never }>>(false); assertType<IsExact<{ prop: { prop: unknown } }, { prop: { prop: any } }>>( false, ); assertType<IsExact<{ prop: { prop: unknown } }, { prop: { prop: never } }>>( false, ); assertType<IsExact<{ prop: { prop: any } }, { prop: { prop: never } }>>( false, ); assertType<IsExact<{ prop: string }, { prop: never }>>(false); assertType<IsExact<{ prop: { prop: any } }, { prop: { prop: string } }>>( false, ); assertType< IsExact< { prop: any } | { prop: string }, { prop: number } | { prop: string } > >(false); assertType<IsExact<{ prop: string | undefined }, { prop?: string }>>(false); // these are different}
// IsAny{ // matching assertType<IsAny<any>>(true);
// not matching assertType<IsAny<string>>(false); assertType<IsAny<unknown>>(false); assertType<IsAny<never>>(false);
// tests for issue #3 (IsAny resolving to boolean) assertType<IsExact<IsAny<string>, false>>(true); assertType<IsExact<IsAny<5>, false>>(true);}
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago