forked from tsdjs/tsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.ts
104 lines (94 loc) · 3.04 KB
/
assert.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Asserts that the type of `expression` is identical to type `T`.
*
* @param expression - Expression that should be identical to type `T`.
*/
// @ts-expect-error
export const expectType = <T>(expression: T) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that the type of `expression` is not identical to type `T`.
*
* @param expression - Expression that should not be identical to type `T`.
*/
// @ts-expect-error
export const expectNotType = <T>(expression: any) => {
// eslint-disable-next-line no-warning-comments
// TODO Use a `not T` type when possible https://github.com/microsoft/TypeScript/pull/29317
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that the type of `expression` is assignable to type `T`.
*
* @param expression - Expression that should be assignable to type `T`.
*/
// @ts-expect-error
export const expectAssignable = <T>(expression: T) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that the type of `expression` is not assignable to type `T`.
*
* @param expression - Expression that should not be assignable to type `T`.
*/
// @ts-expect-error
export const expectNotAssignable = <T>(expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that `expression` throws an error.
*
* @param expression - Expression that should throw an error.
*/
// @ts-expect-error
export const expectError = <T = any>(expression: T) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that `expression` is marked as `@deprecated`.
*
* @param expression - Expression that should be marked as `@deprecated`.
*/
// @ts-expect-error
export const expectDeprecated = (expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that `expression` is not marked as `@deprecated`.
*
* @param expression - Expression that should not be marked as `@deprecated`.
*/
// @ts-expect-error
export const expectNotDeprecated = (expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that the type and return type of `expression` is `never`.
*
* Useful for checking that all branches are covered.
*
* @param expression - Expression that should be `never`.
*/
export const expectNever = (expression: never): never => {
return expression;
};
/**
* Prints the type of `expression` as a warning.
*
* @param expression - Expression whose type should be printed as a warning.
*/
// @ts-expect-error
export const printType = (expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
/**
* Asserts that the documentation comment of `expression` includes string literal type `T`.
*
* @param expression - Expression whose documentation comment should include string literal type `T`.
*/
// @ts-expect-error
export const expectDocCommentIncludes = <T>(expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};