-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.ts
58 lines (50 loc) · 2.4 KB
/
test_utils.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
// deno-lint-ignore-file
// MIT License
//
// Copyright (c) 2020 Anthony Fu <https://github.com/antfu>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ref.
// https://github.com/type-challenges/type-challenges/blob/master/utils/index.d.ts
export type Expect<T extends true> = T;
export type ExpectTrue<T extends true> = T;
export type ExpectFalse<T extends false> = T;
export type IsTrue<T extends true> = T;
export type IsFalse<T extends false> = T;
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends
(<T>() => T extends Y ? 1 : 2) ? true : false;
export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
export type IsAny<T> = 0 extends (1 & T) ? true : false;
export type NotAny<T> = true extends IsAny<T> ? false : true;
export type Debug<T> = { [K in keyof T]: T[K] };
export type MergeInsertions<T> = T extends object
? { [K in keyof T]: MergeInsertions<T[K]> }
: T;
export type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;
export type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true
: false;
export type ExpectValidArgs<
FUNC extends (...args: any[]) => any,
ARGS extends any[],
> = ARGS extends Parameters<FUNC> ? true
: false;
export type UnionToIntersection<U> =
(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I
: never;