@deessejs/type-testing 0.1.0 → 0.1.1

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 (116) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +1 -1
  3. package/.eslintrc.json +0 -7
  4. package/.turbo/turbo-lint.log +0 -24
  5. package/.turbo/turbo-test.log +0 -23
  6. package/.turbo/turbo-typecheck.log +0 -4
  7. package/coverage/base.css +0 -224
  8. package/coverage/block-navigation.js +0 -87
  9. package/coverage/coverage-final.json +0 -15
  10. package/coverage/favicon.png +0 -0
  11. package/coverage/index.html +0 -146
  12. package/coverage/prettify.css +0 -1
  13. package/coverage/prettify.js +0 -2
  14. package/coverage/sort-arrow-sprite.png +0 -0
  15. package/coverage/sorter.js +0 -210
  16. package/coverage/src/api/assert.ts.html +0 -229
  17. package/coverage/src/api/check.ts.html +0 -586
  18. package/coverage/src/api/expect.ts.html +0 -220
  19. package/coverage/src/api/index.html +0 -161
  20. package/coverage/src/api/index.ts.html +0 -106
  21. package/coverage/src/index.html +0 -131
  22. package/coverage/src/index.ts.html +0 -127
  23. package/coverage/src/types/equality.ts.html +0 -190
  24. package/coverage/src/types/function.ts.html +0 -139
  25. package/coverage/src/types/index.html +0 -221
  26. package/coverage/src/types/index.ts.html +0 -121
  27. package/coverage/src/types/inhabitation.ts.html +0 -160
  28. package/coverage/src/types/length.ts.html +0 -109
  29. package/coverage/src/types/property.ts.html +0 -124
  30. package/coverage/src/types/special.ts.html +0 -274
  31. package/coverage/src/types/union.ts.html +0 -193
  32. package/coverage/src/utils.ts.html +0 -136
  33. package/dist/api/assert.d.ts +0 -43
  34. package/dist/api/assert.d.ts.map +0 -1
  35. package/dist/api/assert.js +0 -7
  36. package/dist/api/assert.js.map +0 -1
  37. package/dist/api/check.d.ts +0 -138
  38. package/dist/api/check.d.ts.map +0 -1
  39. package/dist/api/check.js +0 -17
  40. package/dist/api/check.js.map +0 -1
  41. package/dist/api/expect.d.ts +0 -35
  42. package/dist/api/expect.d.ts.map +0 -1
  43. package/dist/api/expect.js +0 -21
  44. package/dist/api/expect.js.map +0 -1
  45. package/dist/api/index.d.ts +0 -7
  46. package/dist/api/index.d.ts.map +0 -1
  47. package/dist/api/index.js +0 -7
  48. package/dist/api/index.js.map +0 -1
  49. package/dist/index.d.ts +0 -9
  50. package/dist/index.d.ts.map +0 -1
  51. package/dist/index.js +0 -12
  52. package/dist/index.js.map +0 -1
  53. package/dist/index.test.d.ts +0 -8
  54. package/dist/index.test.d.ts.map +0 -1
  55. package/dist/index.test.js +0 -264
  56. package/dist/index.test.js.map +0 -1
  57. package/dist/types/equality.d.ts +0 -30
  58. package/dist/types/equality.d.ts.map +0 -1
  59. package/dist/types/equality.js +0 -5
  60. package/dist/types/equality.js.map +0 -1
  61. package/dist/types/function.d.ts +0 -16
  62. package/dist/types/function.d.ts.map +0 -1
  63. package/dist/types/function.js +0 -5
  64. package/dist/types/function.js.map +0 -1
  65. package/dist/types/index.d.ts +0 -11
  66. package/dist/types/index.d.ts.map +0 -1
  67. package/dist/types/index.js +0 -12
  68. package/dist/types/index.js.map +0 -1
  69. package/dist/types/inhabitation.d.ts +0 -24
  70. package/dist/types/inhabitation.d.ts.map +0 -1
  71. package/dist/types/inhabitation.js +0 -5
  72. package/dist/types/inhabitation.js.map +0 -1
  73. package/dist/types/length.d.ts +0 -8
  74. package/dist/types/length.d.ts.map +0 -1
  75. package/dist/types/length.js +0 -5
  76. package/dist/types/length.js.map +0 -1
  77. package/dist/types/property.d.ts +0 -12
  78. package/dist/types/property.d.ts.map +0 -1
  79. package/dist/types/property.js +0 -5
  80. package/dist/types/property.js.map +0 -1
  81. package/dist/types/special.d.ts +0 -55
  82. package/dist/types/special.d.ts.map +0 -1
  83. package/dist/types/special.js +0 -5
  84. package/dist/types/special.js.map +0 -1
  85. package/dist/types/union.d.ts +0 -34
  86. package/dist/types/union.d.ts.map +0 -1
  87. package/dist/types/union.js +0 -5
  88. package/dist/types/union.js.map +0 -1
  89. package/dist/utils.d.ts +0 -14
  90. package/dist/utils.d.ts.map +0 -1
  91. package/dist/utils.js +0 -5
  92. package/dist/utils.js.map +0 -1
  93. package/src/api/assert.ts +0 -48
  94. package/src/api/check.ts +0 -167
  95. package/src/api/expect.ts +0 -45
  96. package/src/api/index.ts +0 -7
  97. package/src/index.ts +0 -14
  98. package/src/types/equality.ts +0 -35
  99. package/src/types/function.ts +0 -18
  100. package/src/types/index.ts +0 -12
  101. package/src/types/inhabitation.ts +0 -25
  102. package/src/types/length.ts +0 -8
  103. package/src/types/property.ts +0 -13
  104. package/src/types/special.ts +0 -63
  105. package/src/types/union.ts +0 -36
  106. package/src/utils.ts +0 -17
  107. package/tests/api.test.ts +0 -40
  108. package/tests/equality.test.ts +0 -57
  109. package/tests/function.test.ts +0 -32
  110. package/tests/inhabitation.test.ts +0 -40
  111. package/tests/length.test.ts +0 -18
  112. package/tests/property.test.ts +0 -35
  113. package/tests/special.test.ts +0 -132
  114. package/tests/union.test.ts +0 -58
  115. package/tests/utils.test.ts +0 -20
  116. package/tsconfig.tsbuildinfo +0 -1
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
package/tests/api.test.ts DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- * API tests.
3
- *
4
- * These tests verify that the type-checking APIs compile correctly.
5
- * The actual type tests are done at compile time.
6
- */
7
-
8
- import { describe, it, expect } from 'vitest'
9
- import { check, assert, expect as expectFn, expectFalse } from '../src'
10
-
11
- describe('check() API', () => {
12
- it('should create check interface', () => {
13
- const c = check<string>()
14
- // Functions return undefined at runtime, but types are checked at compile time
15
- expect(c).toBeUndefined()
16
- })
17
- })
18
-
19
- describe('assert() API', () => {
20
- it('should create assert interface', () => {
21
- const a = assert<string>()
22
- expect(a).toBeUndefined()
23
- })
24
- })
25
-
26
- describe('expect() API', () => {
27
- it('should create expect interface', () => {
28
- const e = expectFn<string, string>()
29
- expect(e).toBeUndefined()
30
- })
31
- })
32
-
33
- describe('expectFalse', () => {
34
- it('should compile for false', () => {
35
- // If this compiles, expectFalse works at compile time
36
- expectFalse<false>()
37
- // Function returns void at runtime
38
- expect(expectFalse<false>()).toBeUndefined()
39
- })
40
- })
@@ -1,57 +0,0 @@
1
- /**
2
- * Type equality tests.
3
- */
4
-
5
- import { describe, it } from 'vitest'
6
- import { Equal, NotEqual, SimpleEqual } from '../src'
7
-
8
- describe('Equal', () => {
9
- it('should detect equal types', () => {
10
- type Test = Equal<string, string>
11
- const _test: Test = true
12
- })
13
-
14
- it('should detect unequal types', () => {
15
- type Test = Equal<string, number>
16
- const _test: Test = false
17
- })
18
-
19
- it('should handle any', () => {
20
- type Test = Equal<any, any>
21
- const _test: Test = true
22
- })
23
-
24
- it('should handle never', () => {
25
- type Test = Equal<never, never>
26
- const _test: Test = true
27
- })
28
-
29
- it('should handle object types', () => {
30
- type Test = Equal<{ a: string }, { a: string }>
31
- const _test: Test = true
32
- })
33
- })
34
-
35
- describe('NotEqual', () => {
36
- it('should detect unequal types', () => {
37
- type Test = NotEqual<string, number>
38
- const _test: Test = true
39
- })
40
-
41
- it('should detect equal types', () => {
42
- type Test = NotEqual<string, string>
43
- const _test: Test = false
44
- })
45
- })
46
-
47
- describe('SimpleEqual', () => {
48
- it('should detect equal types', () => {
49
- type Test = SimpleEqual<string, string>
50
- const _test: Test = true
51
- })
52
-
53
- it('should detect unequal types', () => {
54
- type Test = SimpleEqual<string, number>
55
- const _test: Test = false
56
- })
57
- })
@@ -1,32 +0,0 @@
1
- /**
2
- * Function type tests.
3
- */
4
-
5
- import { describe, it } from 'vitest'
6
- import { Parameters, ReturnType, Parameter } from '../src'
7
-
8
- describe('Parameters', () => {
9
- it('should get function parameters', () => {
10
- type Test = Parameters<(a: string, b: number) => void>
11
- const _test: Test = ['hello', 42]
12
- })
13
- })
14
-
15
- describe('ReturnType', () => {
16
- it('should get function return type', () => {
17
- type Test = ReturnType<(a: string) => number>
18
- const _test: Test = 42
19
- })
20
- })
21
-
22
- describe('Parameter', () => {
23
- it('should get parameter at index 0', () => {
24
- type Test = Parameter<(a: string, b: number) => void, 0>
25
- const _test: Test = 'hello'
26
- })
27
-
28
- it('should get parameter at index 1', () => {
29
- type Test = Parameter<(a: string, b: number) => void, 1>
30
- const _test: Test = 42
31
- })
32
- })