@deessejs/type-testing 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -0
  3. package/dist/api/assert.d.ts.map +1 -1
  4. package/dist/api/assert.js.map +1 -1
  5. package/dist/api/check.d.ts.map +1 -1
  6. package/dist/api/check.js.map +1 -1
  7. package/dist/api/expect.d.ts.map +1 -1
  8. package/dist/api/expect.js.map +1 -1
  9. package/dist/utils.d.ts.map +1 -1
  10. package/package.json +1 -1
  11. package/.eslintrc.json +0 -7
  12. package/.turbo/turbo-lint.log +0 -24
  13. package/.turbo/turbo-test.log +0 -23
  14. package/.turbo/turbo-typecheck.log +0 -4
  15. package/coverage/base.css +0 -224
  16. package/coverage/block-navigation.js +0 -87
  17. package/coverage/coverage-final.json +0 -15
  18. package/coverage/favicon.png +0 -0
  19. package/coverage/index.html +0 -146
  20. package/coverage/prettify.css +0 -1
  21. package/coverage/prettify.js +0 -2
  22. package/coverage/sort-arrow-sprite.png +0 -0
  23. package/coverage/sorter.js +0 -210
  24. package/coverage/src/api/assert.ts.html +0 -229
  25. package/coverage/src/api/check.ts.html +0 -586
  26. package/coverage/src/api/expect.ts.html +0 -220
  27. package/coverage/src/api/index.html +0 -161
  28. package/coverage/src/api/index.ts.html +0 -106
  29. package/coverage/src/index.html +0 -131
  30. package/coverage/src/index.ts.html +0 -127
  31. package/coverage/src/types/equality.ts.html +0 -190
  32. package/coverage/src/types/function.ts.html +0 -139
  33. package/coverage/src/types/index.html +0 -221
  34. package/coverage/src/types/index.ts.html +0 -121
  35. package/coverage/src/types/inhabitation.ts.html +0 -160
  36. package/coverage/src/types/length.ts.html +0 -109
  37. package/coverage/src/types/property.ts.html +0 -124
  38. package/coverage/src/types/special.ts.html +0 -274
  39. package/coverage/src/types/union.ts.html +0 -193
  40. package/coverage/src/utils.ts.html +0 -136
  41. package/src/api/assert.ts +0 -48
  42. package/src/api/check.ts +0 -167
  43. package/src/api/expect.ts +0 -45
  44. package/src/api/index.ts +0 -7
  45. package/src/index.ts +0 -14
  46. package/src/types/equality.ts +0 -35
  47. package/src/types/function.ts +0 -18
  48. package/src/types/index.ts +0 -12
  49. package/src/types/inhabitation.ts +0 -25
  50. package/src/types/length.ts +0 -8
  51. package/src/types/property.ts +0 -13
  52. package/src/types/special.ts +0 -63
  53. package/src/types/union.ts +0 -36
  54. package/src/utils.ts +0 -17
  55. package/tests/api.test.ts +0 -40
  56. package/tests/equality.test.ts +0 -57
  57. package/tests/function.test.ts +0 -32
  58. package/tests/inhabitation.test.ts +0 -40
  59. package/tests/length.test.ts +0 -18
  60. package/tests/property.test.ts +0 -35
  61. package/tests/special.test.ts +0 -132
  62. package/tests/union.test.ts +0 -58
  63. package/tests/utils.test.ts +0 -20
  64. package/tsconfig.tsbuildinfo +0 -1
@@ -1,136 +0,0 @@
1
-
2
- <!doctype html>
3
- <html lang="en">
4
-
5
- <head>
6
- <title>Code coverage report for src/utils.ts</title>
7
- <meta charset="utf-8" />
8
- <link rel="stylesheet" href="../prettify.css" />
9
- <link rel="stylesheet" href="../base.css" />
10
- <link rel="shortcut icon" type="image/x-icon" href="../favicon.png" />
11
- <meta name="viewport" content="width=device-width, initial-scale=1" />
12
- <style type='text/css'>
13
- .coverage-summary .sorter {
14
- background-image: url(../sort-arrow-sprite.png);
15
- }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <div class='wrapper'>
21
- <div class='pad1'>
22
- <h1><a href="../index.html">All files</a> / <a href="index.html">src</a> utils.ts</h1>
23
- <div class='clearfix'>
24
-
25
- <div class='fl pad1y space-right2'>
26
- <span class="strong">0% </span>
27
- <span class="quiet">Statements</span>
28
- <span class='fraction'>0/0</span>
29
- </div>
30
-
31
-
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">0% </span>
34
- <span class="quiet">Branches</span>
35
- <span class='fraction'>0/0</span>
36
- </div>
37
-
38
-
39
- <div class='fl pad1y space-right2'>
40
- <span class="strong">0% </span>
41
- <span class="quiet">Functions</span>
42
- <span class='fraction'>0/0</span>
43
- </div>
44
-
45
-
46
- <div class='fl pad1y space-right2'>
47
- <span class="strong">0% </span>
48
- <span class="quiet">Lines</span>
49
- <span class='fraction'>0/0</span>
50
- </div>
51
-
52
-
53
- </div>
54
- <p class="quiet">
55
- Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
- </p>
57
- <template id="filterTemplate">
58
- <div class="quiet">
59
- Filter:
60
- <input type="search" id="fileSearch">
61
- </div>
62
- </template>
63
- </div>
64
- <div class='status-line low'></div>
65
- <pre><table class="coverage">
66
- <tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
67
- <a name='L2'></a><a href='#L2'>2</a>
68
- <a name='L3'></a><a href='#L3'>3</a>
69
- <a name='L4'></a><a href='#L4'>4</a>
70
- <a name='L5'></a><a href='#L5'>5</a>
71
- <a name='L6'></a><a href='#L6'>6</a>
72
- <a name='L7'></a><a href='#L7'>7</a>
73
- <a name='L8'></a><a href='#L8'>8</a>
74
- <a name='L9'></a><a href='#L9'>9</a>
75
- <a name='L10'></a><a href='#L10'>10</a>
76
- <a name='L11'></a><a href='#L11'>11</a>
77
- <a name='L12'></a><a href='#L12'>12</a>
78
- <a name='L13'></a><a href='#L13'>13</a>
79
- <a name='L14'></a><a href='#L14'>14</a>
80
- <a name='L15'></a><a href='#L15'>15</a>
81
- <a name='L16'></a><a href='#L16'>16</a>
82
- <a name='L17'></a><a href='#L17'>17</a>
83
- <a name='L18'></a><a href='#L18'>18</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
84
- <span class="cline-any cline-neutral">&nbsp;</span>
85
- <span class="cline-any cline-neutral">&nbsp;</span>
86
- <span class="cline-any cline-neutral">&nbsp;</span>
87
- <span class="cline-any cline-neutral">&nbsp;</span>
88
- <span class="cline-any cline-neutral">&nbsp;</span>
89
- <span class="cline-any cline-neutral">&nbsp;</span>
90
- <span class="cline-any cline-neutral">&nbsp;</span>
91
- <span class="cline-any cline-neutral">&nbsp;</span>
92
- <span class="cline-any cline-neutral">&nbsp;</span>
93
- <span class="cline-any cline-neutral">&nbsp;</span>
94
- <span class="cline-any cline-neutral">&nbsp;</span>
95
- <span class="cline-any cline-neutral">&nbsp;</span>
96
- <span class="cline-any cline-neutral">&nbsp;</span>
97
- <span class="cline-any cline-neutral">&nbsp;</span>
98
- <span class="cline-any cline-neutral">&nbsp;</span>
99
- <span class="cline-any cline-neutral">&nbsp;</span>
100
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">/**
101
- * Additional utilities.
102
- */
103
- &nbsp;
104
- import type { Equal } from './types/equality'
105
- &nbsp;
106
- /**
107
- * Type that always resolves to true.
108
- * Useful for making compile-time assertions.
109
- */
110
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
- export type ExpectTrue&lt;_T extends true&gt; = true
112
- &nbsp;
113
- /**
114
- * Type that validates equality and throws if not equal.
115
- */
116
- export type ExpectEqual&lt;T, U&gt; = Equal&lt;T, U&gt; extends true ? T : never
117
- &nbsp;</pre></td></tr></table></pre>
118
-
119
- <div class='push'></div><!-- for sticky footer -->
120
- </div><!-- /wrapper -->
121
- <div class='footer quiet pad2 space-top1 center small'>
122
- Code coverage generated by
123
- <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
124
- at 2026-02-27T13:37:42.407Z
125
- </div>
126
- <script src="../prettify.js"></script>
127
- <script>
128
- window.onload = function () {
129
- prettyPrint();
130
- };
131
- </script>
132
- <script src="../sorter.js"></script>
133
- <script src="../block-navigation.js"></script>
134
- </body>
135
- </html>
136
-
package/src/api/assert.ts DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * Assert API - Alternative API that throws at compile time on failure.
3
- */
4
-
5
- import type { Equal, NotEqual } from '../types/equality'
6
- import type { IsAny, IsNever, IsUnknown, IsVoid, IsUndefined, IsNull, IsNullable, IsOptional } from '../types/special'
7
- import type { IsUnion, IsTuple, IsArray } from '../types/union'
8
- import type { IsInhabited, IsUninhabited } from '../types/inhabitation'
9
- import type { HasProperty } from '../types/property'
10
- import type { Check } from './check'
11
-
12
- /**
13
- * Assert type - alternative API that throws at compile time on failure.
14
- *
15
- * @example
16
- * ```typescript
17
- * assert<string>().equals<string>()
18
- * ```
19
- */
20
- export interface Assert<T> {
21
- equals<U>(): Equal<T, U> extends true ? AssertPass : AssertFail<T, U>
22
- notEquals<U>(): NotEqual<T, U> extends true ? AssertPass : AssertFail<T, U>
23
- extends<U>(): T extends U ? AssertPass : AssertFail<T, U>
24
- hasProperty<K extends keyof T>(): HasProperty<T, K> extends true ? AssertPass : AssertFail<T, { missingProperty: K }>
25
- property<K extends keyof T>(): Check<T[K]>
26
- isAny(): IsAny<T> extends true ? AssertPass : AssertFail<T, 'any'>
27
- isNever(): IsNever<T> extends true ? AssertPass : AssertFail<T, 'never'>
28
- isUnknown(): IsUnknown<T> extends true ? AssertPass : AssertFail<T, 'unknown'>
29
- isVoid(): IsVoid<T> extends true ? AssertPass : AssertFail<T, 'void'>
30
- isUndefined(): IsUndefined<T> extends true ? AssertPass : AssertFail<T, 'undefined'>
31
- isNull(): IsNull<T> extends true ? AssertPass : AssertFail<T, 'null'>
32
- isNullable(): IsNullable<T> extends true ? AssertPass : AssertFail<T, 'not nullable'>
33
- isOptional(): IsOptional<T> extends true ? AssertPass : AssertFail<T, 'not optional'>
34
- isUnion(): IsUnion<T> extends true ? AssertPass : AssertFail<T, 'not a union'>
35
- isTuple(): IsTuple<T> extends true ? AssertPass : AssertFail<T, 'not a tuple'>
36
- isArray(): IsArray<T> extends true ? AssertPass : AssertFail<T, 'not an array'>
37
- isInhabited(): IsInhabited<T> extends true ? AssertPass : AssertFail<T, 'uninhabited'>
38
- isUninhabited(): IsUninhabited<T> extends true ? AssertPass : AssertFail<T, 'inhabited'>
39
- }
40
-
41
- export type AssertPass = true
42
-
43
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
- export type AssertFail<_T, _Expected> = never
45
-
46
- export function assert<T>(): Assert<T> {
47
- return undefined as any
48
- }
package/src/api/check.ts DELETED
@@ -1,167 +0,0 @@
1
- /**
2
- * Check API - Chainable type checker.
3
- */
4
-
5
- import type { Equal, NotEqual } from '../types/equality'
6
- import type { IsAny, IsNever, IsUnknown, IsVoid, IsUndefined, IsNull, IsNullable, IsOptional } from '../types/special'
7
- import type { IsUnion, IsTuple, IsArray } from '../types/union'
8
- import type { IsInhabited, IsUninhabited } from '../types/inhabitation'
9
- import type { HasProperty } from '../types/property'
10
- import type { Parameters, ReturnType, Parameter } from '../types/function'
11
- import type { Length } from '../types/length'
12
-
13
- /**
14
- * Type representing a passing check.
15
- */
16
- export type CheckPass = true
17
-
18
- /**
19
- * Type representing a failing check.
20
- */
21
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
- export type CheckFail<_T, _Expected> = never
23
-
24
- /**
25
- * Helper to create a Check type.
26
- */
27
- export type CheckBuilder<T> = Check<T>
28
-
29
- /**
30
- * Chainable type checker for testing TypeScript types.
31
- *
32
- * @example
33
- * ```typescript
34
- * check<string>().equals<string>()
35
- * check<{ a: string }>().hasProperty('a')
36
- * ```
37
- */
38
- export interface Check<T> {
39
- /**
40
- * Tests if this type equals another type.
41
- */
42
- equals<U>(): Equal<T, U> extends true ? CheckPass : CheckFail<T, U>
43
-
44
- /**
45
- * Tests if this type does not equal another type.
46
- */
47
- notEquals<U>(): NotEqual<T, U> extends true ? CheckPass : CheckFail<T, U>
48
-
49
- /**
50
- * Tests if this type extends another type (is assignable to).
51
- */
52
- extends<U>(): T extends U ? CheckPass : CheckFail<T, U>
53
-
54
- /**
55
- * Tests if this type is assignable from another type.
56
- */
57
- assignableTo<U>(): U extends T ? CheckPass : CheckFail<T, U>
58
-
59
- /**
60
- * Tests if this type has a specific property.
61
- */
62
- hasProperty<K extends keyof T>(): HasProperty<T, K> extends true ? CheckPass : CheckFail<T, { missingProperty: K }>
63
-
64
- /**
65
- * Gets the type of a specific property for further testing.
66
- */
67
- property<K extends keyof T>(): Check<T[K]>
68
-
69
- /**
70
- * Tests if this type is `any`.
71
- */
72
- isAny(): IsAny<T> extends true ? CheckPass : CheckFail<T, 'any'>
73
-
74
- /**
75
- * Tests if this type is `never`.
76
- */
77
- isNever(): IsNever<T> extends true ? CheckPass : CheckFail<T, 'never'>
78
-
79
- /**
80
- * Tests if this type is `unknown`.
81
- */
82
- isUnknown(): IsUnknown<T> extends true ? CheckPass : CheckFail<T, 'unknown'>
83
-
84
- /**
85
- * Tests if this type is `void`.
86
- */
87
- isVoid(): IsVoid<T> extends true ? CheckPass : CheckFail<T, 'void'>
88
-
89
- /**
90
- * Tests if this type is `undefined`.
91
- */
92
- isUndefined(): IsUndefined<T> extends true ? CheckPass : CheckFail<T, 'undefined'>
93
-
94
- /**
95
- * Tests if this type is `null`.
96
- */
97
- isNull(): IsNull<T> extends true ? CheckPass : CheckFail<T, 'null'>
98
-
99
- /**
100
- * Tests if this type is nullable (null or undefined).
101
- */
102
- isNullable(): IsNullable<T> extends true ? CheckPass : CheckFail<T, 'not nullable'>
103
-
104
- /**
105
- * Tests if this type is optional (may be undefined).
106
- */
107
- isOptional(): IsOptional<T> extends true ? CheckPass : CheckFail<T, 'not optional'>
108
-
109
- /**
110
- * Tests if this type is a union.
111
- */
112
- isUnion(): IsUnion<T> extends true ? CheckPass : CheckFail<T, 'not a union'>
113
-
114
- /**
115
- * Tests if this type is a tuple.
116
- */
117
- isTuple(): IsTuple<T> extends true ? CheckPass : CheckFail<T, 'not a tuple'>
118
-
119
- /**
120
- * Tests if this type is an array.
121
- */
122
- isArray(): IsArray<T> extends true ? CheckPass : CheckFail<T, 'not an array'>
123
-
124
- /**
125
- * Tests if this type is inhabited (has values).
126
- */
127
- isInhabited(): IsInhabited<T> extends true ? CheckPass : CheckFail<T, 'uninhabited'>
128
-
129
- /**
130
- * Tests if this type is uninhabited (has no values).
131
- */
132
- isUninhabited(): IsUninhabited<T> extends true ? CheckPass : CheckFail<T, 'inhabited'>
133
-
134
- /**
135
- * Gets the parameters of this function type.
136
- */
137
- parameters(): T extends (...args: any[]) => any ? Check<Parameters<T>> : Check<never>
138
-
139
- /**
140
- * Gets the return type of this function type.
141
- */
142
- returnType(): T extends (...args: any[]) => any ? Check<ReturnType<T>> : Check<never>
143
-
144
- /**
145
- * Gets the length of this array/tuple type.
146
- */
147
- length(): T extends readonly any[] ? Check<Length<T>> : Check<never>
148
-
149
- /**
150
- * Gets the parameter at a specific index.
151
- */
152
- parameter<N extends number>(): T extends (...args: any[]) => any ? Check<Parameter<T, N>> : Check<never>
153
- }
154
-
155
- /**
156
- * Creates a check for a specific type.
157
- *
158
- * @example
159
- * ```typescript
160
- * check<string>().equals<string>()
161
- * check<{ a: string }>().hasProperty('a')
162
- * ```
163
- */
164
- export function check<T>(): CheckBuilder<T> {
165
- // This function exists only at runtime - the types are all compile-time
166
- return undefined as any
167
- }
package/src/api/expect.ts DELETED
@@ -1,45 +0,0 @@
1
- /**
2
- * Expect API - Familiar API similar to testing libraries.
3
- */
4
-
5
- import type { Equal, NotEqual } from '../types/equality'
6
-
7
- /**
8
- * Expect type - familiar API similar to testing libraries.
9
- *
10
- * @example
11
- * ```typescript
12
- * expect<string, string>().toBeEqual()
13
- * expect<string>().toBeAny()
14
- * ```
15
- */
16
- export interface Expect<T, U = unknown> {
17
- toBeEqual(): Equal<T, U> extends true ? ExpectPass : ExpectFail<T, U>
18
- toBeNotEqual(): NotEqual<T, U> extends true ? ExpectPass : ExpectFail<T, U>
19
- toExtend(): T extends U ? ExpectPass : ExpectFail<T, U>
20
- toBeAssignableTo(): U extends T ? ExpectPass : ExpectFail<T, U>
21
- }
22
-
23
- export type ExpectPass = true
24
-
25
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
- export type ExpectFail<_T, _U> = never
27
-
28
- /**
29
- * Creates an expectation for a type.
30
- */
31
- export function expect<T, U = unknown>(): Expect<T, U> {
32
- return undefined as any
33
- }
34
-
35
- /**
36
- * ExpectFalse - for checking types resolve to false.
37
- *
38
- * @example
39
- * ```typescript
40
- * expectFalse<IsNever<string>>()
41
- * ```
42
- */
43
- export function expectFalse<_T extends false>(): void {
44
- // Compile-time only
45
- }
package/src/api/index.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * API exports.
3
- */
4
-
5
- export * from './check'
6
- export * from './assert'
7
- export * from './expect'
package/src/index.ts DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Type-testing: A micro library for testing your TypeScript types.
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- // Re-export all type utilities
8
- export * from './types'
9
-
10
- // Re-export API
11
- export * from './api'
12
-
13
- // Re-export utilities
14
- export * from './utils'
@@ -1,35 +0,0 @@
1
- /**
2
- * Type equality utilities.
3
- */
4
-
5
- /**
6
- * Checks if two types are strictly equal.
7
- * Uses a technique that compares the structure while handling
8
- * special types like any, never, and unknown.
9
- *
10
- * @example
11
- * ```typescript
12
- * check<string>().equals<string>() // passes
13
- * check<string>().equals<number>() // fails at compile time
14
- * ```
15
- */
16
- export type Equal<T, U> =
17
- (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2)
18
- ? true
19
- : false
20
-
21
- /**
22
- * Checks if two types are not equal.
23
- *
24
- * @example
25
- * ```typescript
26
- * check<string>().notEquals<number>() // passes
27
- * ```
28
- */
29
- export type NotEqual<T, U> = Equal<T, U> extends true ? false : true
30
-
31
- /**
32
- * Simple equality check that works in more contexts.
33
- * Useful for simple type comparisons.
34
- */
35
- export type SimpleEqual<T, U> = [T, U] extends [U, T] ? true : false
@@ -1,18 +0,0 @@
1
- /**
2
- * Function type utilities.
3
- */
4
-
5
- /**
6
- * Gets the parameters of a function type as a tuple.
7
- */
8
- export type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never
9
-
10
- /**
11
- * Gets the return type of a function type.
12
- */
13
- export type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : never
14
-
15
- /**
16
- * Gets the parameter type at a specific index.
17
- */
18
- export type Parameter<T extends (...args: any[]) => any, N extends number> = Parameters<T>[N]
@@ -1,12 +0,0 @@
1
- /**
2
- * Type testing utilities.
3
- */
4
-
5
- // Re-export all types
6
- export * from './equality'
7
- export * from './special'
8
- export * from './union'
9
- export * from './inhabitation'
10
- export * from './property'
11
- export * from './function'
12
- export * from './length'
@@ -1,25 +0,0 @@
1
- /**
2
- * Type inhabitation utilities.
3
- */
4
-
5
- /**
6
- * Checks if a type is inhabited (has at least one value).
7
- *
8
- * @example
9
- * ```typescript
10
- * check<string>().isInhabited() // passes
11
- * check<never>().isInhabited() // fails
12
- * ```
13
- */
14
- export type IsInhabited<T> = [T] extends [never] ? false : true
15
-
16
- /**
17
- * Checks if a type is uninhabited (has no values).
18
- *
19
- * @example
20
- * ```typescript
21
- * check<never>().isUninhabited() // passes
22
- * check<string>().isUninhabited() // fails
23
- * ```
24
- */
25
- export type IsUninhabited<T> = [T] extends [never] ? true : false
@@ -1,8 +0,0 @@
1
- /**
2
- * Length utility.
3
- */
4
-
5
- /**
6
- * Gets the length of an array or tuple type.
7
- */
8
- export type Length<T extends readonly any[]> = T['length']
@@ -1,13 +0,0 @@
1
- /**
2
- * Property testing utilities.
3
- */
4
-
5
- /**
6
- * Checks if a type has a specific property.
7
- */
8
- export type HasProperty<T, K extends PropertyKey> = K extends keyof T ? true : false
9
-
10
- /**
11
- * Gets the type of a specific property from a type.
12
- */
13
- export type PropertyType<T, K extends keyof T> = T[K]
@@ -1,63 +0,0 @@
1
- /**
2
- * Special type detection utilities.
3
- */
4
-
5
- import type { Equal } from './equality'
6
-
7
- /**
8
- * Checks if a type is `any`.
9
- * Uses the technique: 0 extends (1 & T) ? true : false
10
- *
11
- * @example
12
- * ```typescript
13
- * check<any>().isAny() // passes
14
- * check<string>().isAny() // fails
15
- * ```
16
- */
17
- export type IsAny<T> = 0 extends (1 & T) ? true : false
18
-
19
- /**
20
- * Checks if a type is `never`.
21
- *
22
- * @example
23
- * ```typescript
24
- * check<never>().isNever() // passes
25
- * check<string>().isNever() // fails
26
- * ```
27
- */
28
- export type IsNever<T> = [T] extends [never] ? true : false
29
-
30
- /**
31
- * Checks if a type is `unknown`.
32
- *
33
- * @example
34
- * ```typescript
35
- * check<unknown>().isUnknown() // passes
36
- * ```
37
- */
38
- export type IsUnknown<T> = [unknown] extends [T] ? ([T] extends [unknown] ? true : false) : false
39
-
40
- /**
41
- * Checks if a type is `void`.
42
- */
43
- export type IsVoid<T> = Equal<T, void>
44
-
45
- /**
46
- * Checks if a type is `undefined`.
47
- */
48
- export type IsUndefined<T> = Equal<T, undefined>
49
-
50
- /**
51
- * Checks if a type is `null`.
52
- */
53
- export type IsNull<T> = Equal<T, null>
54
-
55
- /**
56
- * Checks if a type is `null` or `undefined`.
57
- */
58
- export type IsNullable<T> = [null] extends [T] ? true : ([undefined] extends [T] ? true : false)
59
-
60
- /**
61
- * Checks if a type is optional (may be undefined).
62
- */
63
- export type IsOptional<T> = [undefined] extends [T] ? true : false
@@ -1,36 +0,0 @@
1
- /**
2
- * Union and tuple detection utilities.
3
- */
4
-
5
- /**
6
- * Checks if a type is a union.
7
- *
8
- * @example
9
- * ```typescript
10
- * check<'a' | 'b'>().isUnion() // passes
11
- * check<'a'>().isUnion() // fails
12
- * ```
13
- */
14
- export type IsUnion<T, U = T> = [U] extends [never] ? false : T extends U ? [Exclude<U, never>] extends [T] ? false : true : false
15
-
16
- /**
17
- * Checks if a type is a tuple.
18
- *
19
- * @example
20
- * ```typescript
21
- * check<[string, number]>().isTuple() // passes
22
- * check<string[]>().isTuple() // fails
23
- * ```
24
- */
25
- export type IsTuple<T> = T extends readonly any[] ? (number extends T['length'] ? false : true) : false
26
-
27
- /**
28
- * Checks if a type is an array.
29
- *
30
- * @example
31
- * ```typescript
32
- * check<string[]>().isArray() // passes
33
- * check<[string]>().isArray() // fails
34
- * ```
35
- */
36
- export type IsArray<T> = T extends readonly any[] ? (IsTuple<T> extends true ? false : true) : false
package/src/utils.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Additional utilities.
3
- */
4
-
5
- import type { Equal } from './types/equality'
6
-
7
- /**
8
- * Type that always resolves to true.
9
- * Useful for making compile-time assertions.
10
- */
11
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
- export type ExpectTrue<_T extends true> = true
13
-
14
- /**
15
- * Type that validates equality and throws if not equal.
16
- */
17
- export type ExpectEqual<T, U> = Equal<T, U> extends true ? T : never