Skip to content

Commit 76123b0

Browse files
authored
feat: assert event
1 parent a786b3f commit 76123b0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

src/assert/index.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
3+
/**
4+
* Check that the type of `value` is identical to type `T`.
5+
*
6+
* @param value - Value that should be identical to type `T`.
7+
*/
8+
// @ts-expect-error
9+
export const expectType = <T>(value: T) => {
10+
// Do nothing, the TypeScript compiler handles this for us
11+
};
12+
13+
/**
14+
* Check that the type of `value` is not identical to type `T`.
15+
*
16+
* @param value - Value that should be identical to type `T`.
17+
*/
18+
// @ts-expect-error
19+
export const expectNotType = <T>(value: any) => {
20+
// eslint-disable-next-line no-warning-comments
21+
// TODO Use a `not T` type when possible https://github.com/microsoft/TypeScript/pull/29317
22+
// Do nothing, the TypeScript compiler handles this for us
23+
};
24+
25+
/**
26+
* Check that the type of `value` is assignable to type `T`.
27+
*
28+
* @param value - Value that should be assignable to type `T`.
29+
*/
30+
// @ts-expect-error
31+
export const expectAssignable = <T>(value: T) => {
32+
// Do nothing, the TypeScript compiler handles this for us
33+
};
34+
35+
/**
36+
* Check that the type of `value` is not assignable to type `T`.
37+
*
38+
* @param value - Value that should not be assignable to type `T`.
39+
*/
40+
// @ts-expect-error
41+
export const expectNotAssignable = <T>(value: any) => {
42+
// Do nothing, the TypeScript compiler handles this for us
43+
};
44+
45+
/**
46+
* Assert the value to throw an argument error.
47+
*
48+
* @param value - Value that should be checked.
49+
*/
50+
// @ts-expect-error
51+
export const expectError = <T = any>(value: T) => {
52+
// Do nothing, the TypeScript compiler handles this for us
53+
};
54+
55+
/**
56+
* Assert that the `expression` provided is marked as `@deprecated`.
57+
*
58+
* @param expression - Expression that should be marked as `@deprecated`.
59+
*/
60+
// @ts-expect-error
61+
export const expectDeprecated = (expression: any) => {
62+
// Do nothing, the TypeScript compiler handles this for us
63+
};
64+
65+
/**
66+
* Assert that the `expression` provided is not marked as `@deprecated`.
67+
*
68+
* @param expression - Expression that should not be marked as `@deprecated`.
69+
*/
70+
// @ts-expect-error
71+
export const expectNotDeprecated = (expression: any) => {
72+
// Do nothing, the TypeScript compiler handles this for us
73+
};
74+
75+
/**
76+
* Will print a warning with the type of the expression passed as argument.
77+
*
78+
* @param expression - Expression whose type should be printed as a warning.
79+
*/
80+
// @ts-expect-error
81+
export const printType = (expression: any) => {
82+
// Do nothing, the TypeScript compiler handles this for us
83+
};

0 commit comments

Comments
 (0)