All files / testing / types.ts

100.00% Branches 0/0
100.00% Lines 7/7
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
x1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
x1
x1
x1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
x1
x1
x1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 













































































































































































































































































































/**
 * Testing utilities for types.
 *
 * ```ts expect-error ignore
 * import { assertType, IsExact, IsNullable } from "@std/testing/types";
 *
 * const result = "some result" as string | number;
 *
 * // compile error if the type of `result` is not exactly `string | number`
 * assertType<IsExact<typeof result, string | number>>(true);
 *
 * // causes a compile error that `true` is not assignable to `false`
 * assertType<IsNullable<string>>(true); // error: string is not nullable
 * ```
 *
 * @module
 */
import { assertType as _function_assertType } from "jsr:@std/[email protected]/types"
/**
 * Asserts at compile time that the provided type argument's type resolves to the expected boolean literal type.
 *
 * @example Usage
 * ```ts expect-error ignore
 * import { assertType, IsExact, IsNullable } from "@std/testing/types";
 *
 * const result = "some result" as string | number;
 *
 * // compile error if the type of `result` is not exactly `string | number`
 * assertType<IsExact<typeof result, string | number>>(true);
 *
 * // causes a compile error that `true` is not assignable to `false`
 * assertType<IsNullable<string>>(true); // error: string is not nullable
 * ```
 *
 * @template T The expected type (`true` or `false`)
 * @param expectTrue True if the passed in type argument resolved to true.
 */
const assertType = _function_assertType as typeof _function_assertType
export { assertType }

import type { AssertTrue as _typeAlias_AssertTrue } from "jsr:@std/[email protected]/types"
/**
 * Asserts at compile time that the provided type argument's type resolves to true.
 *
 * @example Usage
 * ```ts
 * import { AssertTrue, Has, IsNullable } from "@std/testing/types";
 *
 * const result = 1 as string | number | null;
 *
 * type doTest = AssertTrue<Has<typeof result, string> | IsNullable<typeof result>>;
 * ```
 *
 * @template T The type to assert is true.
 */
type AssertTrue<T extends true> = _typeAlias_AssertTrue<T>
export type { AssertTrue }

import type { AssertFalse as _typeAlias_AssertFalse } from "jsr:@std/[email protected]/types"
/**
 * Asserts at compile time that the provided type argument's type resolves to false.
 *
 * @example Usage
 * ```ts
 * import { AssertFalse, IsNever } from "@std/testing/types";
 *
 * const result = 1 as string | number | null;
 *
 * type doTest = AssertFalse<IsNever<typeof result>>;
 * ```
 *
 * @template T The type to assert is false.
 */
type AssertFalse<T extends false> = _typeAlias_AssertFalse<T>
export type { AssertFalse }

import type { Assert as _typeAlias_Assert } from "jsr:@std/[email protected]/types"
/**
 * Asserts at compile time that the provided type argument's type resolves to the expected boolean literal type.
 *
 * @example Usage
 * ```ts
 * import { Assert, Has } from "@std/testing/types";
 *
 * const result = 1 as string | number | null;
 *
 * type doTest = Assert<Has<typeof result, number>, true>;
 * ```
 *
 * @template T The type to assert is the expected boolean literal type.
 * @template Expected The expected boolean literal type.
 */
type Assert<T extends boolean, Expected extends T> = _typeAlias_Assert<T, Expected>
export type { Assert }

import type { Has as _typeAlias_Has } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` has the specified type `U`.
 *
 * @example Usage
 * ```ts
 * import { assertType, Has } from "@std/testing/types";
 *
 * assertType<Has<string | number, string>>(true);
 * assertType<Has<any, number>>(true);
 *
 * assertType<Has<string | number, Date>>(false);
 * assertType<Has<string, number>>(false);
 * assertType<Has<number, any>>(false);
 * ```
 *
 * @template T The type to check if it has the specified type `U`.
 * @template U The type to check if it is in the type `T`.
 */
type Has<T, U> = _typeAlias_Has<T, U>
export type { Has }

import type { NotHas as _typeAlias_NotHas } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` does not have the specified type `U`.
 *
 * @example Usage
 * ```ts
 * import { assertType, NotHas } from "@std/testing/types";
 *
 * assertType<NotHas<string | number, Date>>(true);
 * assertType<NotHas<string, number>>(true);
 * assertType<NotHas<number, any>>(true);
 *
 * assertType<NotHas<string | number, string>>(false);
 * assertType<NotHas<any, number>>(false);
 * ```
 *
 * @template T The type to check if it does not have the specified type `U`.
 * @template U The type to check if it is not in the type `T`.
 */
type NotHas<T, U> = _typeAlias_NotHas<T, U>
export type { NotHas }

import type { IsNullable as _typeAlias_IsNullable } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` is possibly null or undefined.
 *
 * @example Usage
 * ```ts
 * import { assertType, IsNullable } from "@std/testing/types";
 *
 * assertType<IsNullable<string | null>>(true);
 * assertType<IsNullable<string | undefined>>(true);
 * assertType<IsNullable<null | undefined>>(true);
 *
 * assertType<IsNullable<string>>(false);
 * assertType<IsNullable<any>>(false);
 * assertType<IsNullable<never>>(false);
 * ```
 *
 * @template T The type to check if it is nullable.
 */
type IsNullable<T> = _typeAlias_IsNullable<T>
export type { IsNullable }

import type { IsExact as _typeAlias_IsExact } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` exactly matches type `U`.
 *
 * @example Usage
 * ```ts
 * import { assertType, IsExact } from "@std/testing/types";
 *
 * assertType<IsExact<string | number, string | number>>(true);
 * assertType<IsExact<any, any>>(true); // ok to have any for both
 * assertType<IsExact<never, never>>(true);
 * assertType<IsExact<{ prop: string }, { prop: string }>>(true);
 *
 * 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);
 * ```
 *
 * @template T The type to check if it exactly matches type `U`.
 * @template U The type to check if it exactly matches type `T`.
 */
type IsExact<T, U> = _typeAlias_IsExact<T, U>
export type { IsExact }

import type { DeepPrepareIsExact as _typeAlias_DeepPrepareIsExact } from "jsr:@std/[email protected]/types"
/**
 * @internal
 */
type DeepPrepareIsExact<T, VisitedTypes = never> = _typeAlias_DeepPrepareIsExact<T, VisitedTypes>
export type { DeepPrepareIsExact }

import type { DeepPrepareIsExactProp as _typeAlias_DeepPrepareIsExactProp } from "jsr:@std/[email protected]/types"
/**
 * @internal
 */
type DeepPrepareIsExactProp<Prop, Parent, VisitedTypes> = _typeAlias_DeepPrepareIsExactProp<Prop, Parent, VisitedTypes>
export type { DeepPrepareIsExactProp }

import type { IsAny as _typeAlias_IsAny } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` is the `any` type.
 *
 * @example Usage
 * ```ts
 * import { assertType, IsAny } from "@std/testing/types";
 *
 * assertType<IsAny<any>>(true);
 * assertType<IsAny<unknown>>(false);
 * ```
 *
 * @template T The type to check if it is the `any` type.
 */
type IsAny<T> = _typeAlias_IsAny<T>
export type { IsAny }

import type { IsNever as _typeAlias_IsNever } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` is the `never` type.
 *
 * @example Usage
 * ```ts
 * import { assertType, IsNever } from "@std/testing/types";
 *
 * assertType<IsNever<never>>(true);
 * assertType<IsNever<unknown>>(false);
 * ```
 *
 * @template T The type to check if it is the `never` type.
 */
type IsNever<T> = _typeAlias_IsNever<T>
export type { IsNever }

import type { IsUnknown as _typeAlias_IsUnknown } from "jsr:@std/[email protected]/types"
/**
 * Checks if type `T` is the `unknown` type.
 *
 * @example Usage
 * ```ts
 * import { assertType, IsUnknown } from "@std/testing/types";
 *
 * assertType<IsUnknown<unknown>>(true);
 * assertType<IsUnknown<never>>(false);
 * ```
 *
 * @template T The type to check if it is the `unknown` type.
 */
type IsUnknown<T> = _typeAlias_IsUnknown<T>
export type { IsUnknown }

import type { ParametersAndReturnTypeMatches as _typeAlias_ParametersAndReturnTypeMatches } from "jsr:@std/[email protected]/types"
/**
 * The internal utility type to match the given types as return types.
 *
 * @internal
 */
type ParametersAndReturnTypeMatches<T, U> = _typeAlias_ParametersAndReturnTypeMatches<T, U>
export type { ParametersAndReturnTypeMatches }

import type { TupleMatches as _typeAlias_TupleMatches } from "jsr:@std/[email protected]/types"
/**
 * The internal utility type to match the given types as tuples.
 *
 * @internal
 */
type TupleMatches<T, U> = _typeAlias_TupleMatches<T, U>
export type { TupleMatches }

import type { Matches as _typeAlias_Matches } from "jsr:@std/[email protected]/types"
/**
 * The internal utility type to match the given types.
 *
 * @internal
 */
type Matches<T, U> = _typeAlias_Matches<T, U>
export type { Matches }

import type { AnyToBrand as _typeAlias_AnyToBrand } from "jsr:@std/[email protected]/types"
/**
 * The utility type to convert any to {@linkcode AnyBrand}.
 *
 * @internal
 */
type AnyToBrand<T> = _typeAlias_AnyToBrand<T>
export type { AnyToBrand }

import type { AnyBrand as _typeAlias_AnyBrand } from "jsr:@std/[email protected]/types"
/**
 * The utility type to represent any type.
 *
 * @internal
 */
type AnyBrand = _typeAlias_AnyBrand
export type { AnyBrand }

import type { FlatType as _typeAlias_FlatType } from "jsr:@std/[email protected]/types"
/**
 * The utility type to flatten record types.
 *
 * @internal
 */
type FlatType<T> = _typeAlias_FlatType<T>
export type { FlatType }