@deessejs/type-testing 0.1.1 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -0
- package/dist/api/assert.d.ts +43 -0
- package/dist/api/assert.d.ts.map +1 -0
- package/dist/api/assert.js +7 -0
- package/dist/api/assert.js.map +1 -0
- package/dist/api/check.d.ts +138 -0
- package/dist/api/check.d.ts.map +1 -0
- package/dist/api/check.js +17 -0
- package/dist/api/check.js.map +1 -0
- package/dist/api/expect.d.ts +35 -0
- package/dist/api/expect.d.ts.map +1 -0
- package/dist/api/expect.js +21 -0
- package/dist/api/expect.js.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +7 -0
- package/dist/api/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +8 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +264 -0
- package/dist/index.test.js.map +1 -0
- package/dist/types/equality.d.ts +30 -0
- package/dist/types/equality.d.ts.map +1 -0
- package/dist/types/equality.js +5 -0
- package/dist/types/equality.js.map +1 -0
- package/dist/types/function.d.ts +16 -0
- package/dist/types/function.d.ts.map +1 -0
- package/dist/types/function.js +5 -0
- package/dist/types/function.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inhabitation.d.ts +24 -0
- package/dist/types/inhabitation.d.ts.map +1 -0
- package/dist/types/inhabitation.js +5 -0
- package/dist/types/inhabitation.js.map +1 -0
- package/dist/types/length.d.ts +8 -0
- package/dist/types/length.d.ts.map +1 -0
- package/dist/types/length.js +5 -0
- package/dist/types/length.js.map +1 -0
- package/dist/types/property.d.ts +12 -0
- package/dist/types/property.d.ts.map +1 -0
- package/dist/types/property.js +5 -0
- package/dist/types/property.js.map +1 -0
- package/dist/types/special.d.ts +55 -0
- package/dist/types/special.d.ts.map +1 -0
- package/dist/types/special.js +5 -0
- package/dist/types/special.js.map +1 -0
- package/dist/types/union.d.ts +34 -0
- package/dist/types/union.d.ts.map +1 -0
- package/dist/types/union.js +5 -0
- package/dist/types/union.js.map +1 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ A micro library for compile-time type testing in TypeScript.
|
|
|
7
7
|
[](https://www.npmjs.com/package/@deessejs/type-testing)
|
|
8
8
|
[](https://www.npmjs.com/package/@deessejs/type-testing)
|
|
9
9
|
[](https://www.typescriptlang.org/)
|
|
10
|
+
[](https://github.com/nesalia-inc/type-testing/actions)
|
|
10
11
|
[](https://opensource.org/licenses/MIT)
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assert API - Alternative API that throws at compile time on failure.
|
|
3
|
+
*/
|
|
4
|
+
import type { Equal, NotEqual } from '../types/equality';
|
|
5
|
+
import type { IsAny, IsNever, IsUnknown, IsVoid, IsUndefined, IsNull, IsNullable, IsOptional } from '../types/special';
|
|
6
|
+
import type { IsUnion, IsTuple, IsArray } from '../types/union';
|
|
7
|
+
import type { IsInhabited, IsUninhabited } from '../types/inhabitation';
|
|
8
|
+
import type { HasProperty } from '../types/property';
|
|
9
|
+
import type { Check } from './check';
|
|
10
|
+
/**
|
|
11
|
+
* Assert type - alternative API that throws at compile time on failure.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* assert<string>().equals<string>()
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface Assert<T> {
|
|
19
|
+
equals<U>(): Equal<T, U> extends true ? AssertPass : AssertFail<T, U>;
|
|
20
|
+
notEquals<U>(): NotEqual<T, U> extends true ? AssertPass : AssertFail<T, U>;
|
|
21
|
+
extends<U>(): T extends U ? AssertPass : AssertFail<T, U>;
|
|
22
|
+
hasProperty<K extends keyof T>(): HasProperty<T, K> extends true ? AssertPass : AssertFail<T, {
|
|
23
|
+
missingProperty: K;
|
|
24
|
+
}>;
|
|
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
|
+
export type AssertPass = true;
|
|
41
|
+
export type AssertFail<_T, _Expected> = never;
|
|
42
|
+
export declare function assert<T>():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,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,CAAA;IAC9E,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,cAAc,CAAC,CAAA;IAC/E,WAAW,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,CAAA;IACtF,aAAa,IAAI,aAAa,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,WAAW,CAAC,CAAA;CACzF;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAA;AAE7B,MAAM,MAAM,UAAU,CAAC,EAAE,EAAE,SAAS,IAAI,KAAK,CAAA;AAE7C,wBAAgB,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAErC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/api/assert.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0CH,MAAM,UAAU,MAAM;IACpB,OAAO,SAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check API - Chainable type checker.
|
|
3
|
+
*/
|
|
4
|
+
import type { Equal, NotEqual } from '../types/equality';
|
|
5
|
+
import type { IsAny, IsNever, IsUnknown, IsVoid, IsUndefined, IsNull, IsNullable, IsOptional } from '../types/special';
|
|
6
|
+
import type { IsUnion, IsTuple, IsArray } from '../types/union';
|
|
7
|
+
import type { IsInhabited, IsUninhabited } from '../types/inhabitation';
|
|
8
|
+
import type { HasProperty } from '../types/property';
|
|
9
|
+
import type { Parameters, ReturnType, Parameter } from '../types/function';
|
|
10
|
+
import type { Length } from '../types/length';
|
|
11
|
+
/**
|
|
12
|
+
* Type representing a passing check.
|
|
13
|
+
*/
|
|
14
|
+
export type CheckPass = true;
|
|
15
|
+
/**
|
|
16
|
+
* Type representing a failing check.
|
|
17
|
+
*/
|
|
18
|
+
export type CheckFail<_T, _Expected> = never;
|
|
19
|
+
/**
|
|
20
|
+
* Helper to create a Check type.
|
|
21
|
+
*/
|
|
22
|
+
export type CheckBuilder<T> = Check<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Chainable type checker for testing TypeScript types.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* check<string>().equals<string>()
|
|
29
|
+
* check<{ a: string }>().hasProperty('a')
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface Check<T> {
|
|
33
|
+
/**
|
|
34
|
+
* Tests if this type equals another type.
|
|
35
|
+
*/
|
|
36
|
+
equals<U>(): Equal<T, U> extends true ? CheckPass : CheckFail<T, U>;
|
|
37
|
+
/**
|
|
38
|
+
* Tests if this type does not equal another type.
|
|
39
|
+
*/
|
|
40
|
+
notEquals<U>(): NotEqual<T, U> extends true ? CheckPass : CheckFail<T, U>;
|
|
41
|
+
/**
|
|
42
|
+
* Tests if this type extends another type (is assignable to).
|
|
43
|
+
*/
|
|
44
|
+
extends<U>(): T extends U ? CheckPass : CheckFail<T, U>;
|
|
45
|
+
/**
|
|
46
|
+
* Tests if this type is assignable from another type.
|
|
47
|
+
*/
|
|
48
|
+
assignableTo<U>(): U extends T ? CheckPass : CheckFail<T, U>;
|
|
49
|
+
/**
|
|
50
|
+
* Tests if this type has a specific property.
|
|
51
|
+
*/
|
|
52
|
+
hasProperty<K extends keyof T>(): HasProperty<T, K> extends true ? CheckPass : CheckFail<T, {
|
|
53
|
+
missingProperty: K;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the type of a specific property for further testing.
|
|
57
|
+
*/
|
|
58
|
+
property<K extends keyof T>(): Check<T[K]>;
|
|
59
|
+
/**
|
|
60
|
+
* Tests if this type is `any`.
|
|
61
|
+
*/
|
|
62
|
+
isAny(): IsAny<T> extends true ? CheckPass : CheckFail<T, 'any'>;
|
|
63
|
+
/**
|
|
64
|
+
* Tests if this type is `never`.
|
|
65
|
+
*/
|
|
66
|
+
isNever(): IsNever<T> extends true ? CheckPass : CheckFail<T, 'never'>;
|
|
67
|
+
/**
|
|
68
|
+
* Tests if this type is `unknown`.
|
|
69
|
+
*/
|
|
70
|
+
isUnknown(): IsUnknown<T> extends true ? CheckPass : CheckFail<T, 'unknown'>;
|
|
71
|
+
/**
|
|
72
|
+
* Tests if this type is `void`.
|
|
73
|
+
*/
|
|
74
|
+
isVoid(): IsVoid<T> extends true ? CheckPass : CheckFail<T, 'void'>;
|
|
75
|
+
/**
|
|
76
|
+
* Tests if this type is `undefined`.
|
|
77
|
+
*/
|
|
78
|
+
isUndefined(): IsUndefined<T> extends true ? CheckPass : CheckFail<T, 'undefined'>;
|
|
79
|
+
/**
|
|
80
|
+
* Tests if this type is `null`.
|
|
81
|
+
*/
|
|
82
|
+
isNull(): IsNull<T> extends true ? CheckPass : CheckFail<T, 'null'>;
|
|
83
|
+
/**
|
|
84
|
+
* Tests if this type is nullable (null or undefined).
|
|
85
|
+
*/
|
|
86
|
+
isNullable(): IsNullable<T> extends true ? CheckPass : CheckFail<T, 'not nullable'>;
|
|
87
|
+
/**
|
|
88
|
+
* Tests if this type is optional (may be undefined).
|
|
89
|
+
*/
|
|
90
|
+
isOptional(): IsOptional<T> extends true ? CheckPass : CheckFail<T, 'not optional'>;
|
|
91
|
+
/**
|
|
92
|
+
* Tests if this type is a union.
|
|
93
|
+
*/
|
|
94
|
+
isUnion(): IsUnion<T> extends true ? CheckPass : CheckFail<T, 'not a union'>;
|
|
95
|
+
/**
|
|
96
|
+
* Tests if this type is a tuple.
|
|
97
|
+
*/
|
|
98
|
+
isTuple(): IsTuple<T> extends true ? CheckPass : CheckFail<T, 'not a tuple'>;
|
|
99
|
+
/**
|
|
100
|
+
* Tests if this type is an array.
|
|
101
|
+
*/
|
|
102
|
+
isArray(): IsArray<T> extends true ? CheckPass : CheckFail<T, 'not an array'>;
|
|
103
|
+
/**
|
|
104
|
+
* Tests if this type is inhabited (has values).
|
|
105
|
+
*/
|
|
106
|
+
isInhabited(): IsInhabited<T> extends true ? CheckPass : CheckFail<T, 'uninhabited'>;
|
|
107
|
+
/**
|
|
108
|
+
* Tests if this type is uninhabited (has no values).
|
|
109
|
+
*/
|
|
110
|
+
isUninhabited(): IsUninhabited<T> extends true ? CheckPass : CheckFail<T, 'inhabited'>;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the parameters of this function type.
|
|
113
|
+
*/
|
|
114
|
+
parameters(): T extends (...args: any[]) => any ? Check<Parameters<T>> : Check<never>;
|
|
115
|
+
/**
|
|
116
|
+
* Gets the return type of this function type.
|
|
117
|
+
*/
|
|
118
|
+
returnType(): T extends (...args: any[]) => any ? Check<ReturnType<T>> : Check<never>;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the length of this array/tuple type.
|
|
121
|
+
*/
|
|
122
|
+
length(): T extends readonly any[] ? Check<Length<T>> : Check<never>;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the parameter at a specific index.
|
|
125
|
+
*/
|
|
126
|
+
parameter<N extends number>(): T extends (...args: any[]) => any ? Check<Parameter<T, N>> : Check<never>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates a check for a specific type.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* check<string>().equals<string>()
|
|
134
|
+
* check<{ a: string }>().hasProperty('a')
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function check<T>(): CheckBuilder<T>;
|
|
138
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/api/check.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM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EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IAEpE;;OAEG;IACH,SAAS,CAAC,CAAC,SAAS,MAAM,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;CACzG;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAG1C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check API - Chainable type checker.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates a check for a specific type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* check<string>().equals<string>()
|
|
10
|
+
* check<{ a: string }>().hasProperty('a')
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function check() {
|
|
14
|
+
// This function exists only at runtime - the types are all compile-time
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/api/check.ts"],"names":[],"mappings":"AAAA;;GAEG;AAuJH;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK;IACnB,wEAAwE;IACxE,OAAO,SAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expect API - Familiar API similar to testing libraries.
|
|
3
|
+
*/
|
|
4
|
+
import type { Equal, NotEqual } from '../types/equality';
|
|
5
|
+
/**
|
|
6
|
+
* Expect type - familiar API similar to testing libraries.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* expect<string, string>().toBeEqual()
|
|
11
|
+
* expect<string>().toBeAny()
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface Expect<T, U = unknown> {
|
|
15
|
+
toBeEqual(): Equal<T, U> extends true ? ExpectPass : ExpectFail<T, U>;
|
|
16
|
+
toBeNotEqual(): NotEqual<T, U> extends true ? ExpectPass : ExpectFail<T, U>;
|
|
17
|
+
toExtend(): T extends U ? ExpectPass : ExpectFail<T, U>;
|
|
18
|
+
toBeAssignableTo(): U extends T ? ExpectPass : ExpectFail<T, U>;
|
|
19
|
+
}
|
|
20
|
+
export type ExpectPass = true;
|
|
21
|
+
export type ExpectFail<_T, _U> = never;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an expectation for a type.
|
|
24
|
+
*/
|
|
25
|
+
export declare function expect<T, U = unknown>(): Expect<T, U>;
|
|
26
|
+
/**
|
|
27
|
+
* ExpectFalse - for checking types resolve to false.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* expectFalse<IsNever<string>>()
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function expectFalse<_T extends false>(): void;
|
|
35
|
+
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/api/expect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAExD;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO;IACpC,SAAS,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACrE,YAAY,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC3E,QAAQ,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACvD,gBAAgB,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAChE;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAA;AAE7B,MAAM,MAAM,UAAU,CAAC,EAAE,EAAE,EAAE,IAAI,KAAK,CAAA;AAEtC;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAErD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,SAAS,KAAK,KAAK,IAAI,CAEpD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expect API - Familiar API similar to testing libraries.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates an expectation for a type.
|
|
6
|
+
*/
|
|
7
|
+
export function expect() {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* ExpectFalse - for checking types resolve to false.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* expectFalse<IsNever<string>>()
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function expectFalse() {
|
|
19
|
+
// Compile-time only
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=expect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/api/expect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwBH;;GAEG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,SAAgB,CAAA;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW;IACzB,oBAAoB;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,SAAS,CAAA;AAGvB,cAAc,OAAO,CAAA;AAGrB,cAAc,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-testing: A micro library for testing your TypeScript types.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
// Re-export all type utilities
|
|
7
|
+
export * from './types';
|
|
8
|
+
// Re-export API
|
|
9
|
+
export * from './api';
|
|
10
|
+
// Re-export utilities
|
|
11
|
+
export * from './utils';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,SAAS,CAAA;AAEvB,gBAAgB;AAChB,cAAc,OAAO,CAAA;AAErB,sBAAsB;AACtB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-testing tests
|
|
3
|
+
*
|
|
4
|
+
* These tests verify that the type-checking utilities compile correctly.
|
|
5
|
+
* If the code compiles, the types are correct.
|
|
6
|
+
*/
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
|
+
import { describe, it } from 'vitest';
|
|
9
|
+
import {
|
|
10
|
+
// Main exports
|
|
11
|
+
check, assert, expect, expectFalse, } from './index';
|
|
12
|
+
// These tests verify that the types compile correctly.
|
|
13
|
+
// The actual type tests are done at compile time.
|
|
14
|
+
describe('Equal', () => {
|
|
15
|
+
it('should detect equal types', () => {
|
|
16
|
+
const _test = true;
|
|
17
|
+
});
|
|
18
|
+
it('should detect unequal types', () => {
|
|
19
|
+
const _test = false;
|
|
20
|
+
});
|
|
21
|
+
it('should handle any', () => {
|
|
22
|
+
const _test = true;
|
|
23
|
+
});
|
|
24
|
+
it('should handle never', () => {
|
|
25
|
+
const _test = true;
|
|
26
|
+
});
|
|
27
|
+
it('should handle object types', () => {
|
|
28
|
+
const _test = true;
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('NotEqual', () => {
|
|
32
|
+
it('should detect unequal types', () => {
|
|
33
|
+
const _test = true;
|
|
34
|
+
});
|
|
35
|
+
it('should detect equal types', () => {
|
|
36
|
+
const _test = false;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('IsAny', () => {
|
|
40
|
+
it('should detect any', () => {
|
|
41
|
+
const _test = true;
|
|
42
|
+
});
|
|
43
|
+
it('should not detect string as any', () => {
|
|
44
|
+
const _test = false;
|
|
45
|
+
});
|
|
46
|
+
it('should not detect never as any', () => {
|
|
47
|
+
const _test = false;
|
|
48
|
+
});
|
|
49
|
+
it('should not detect unknown as any', () => {
|
|
50
|
+
const _test = false;
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('IsNever', () => {
|
|
54
|
+
it('should detect never', () => {
|
|
55
|
+
const _test = true;
|
|
56
|
+
});
|
|
57
|
+
it('should not detect string as never', () => {
|
|
58
|
+
const _test = false;
|
|
59
|
+
});
|
|
60
|
+
it('should not detect any as never', () => {
|
|
61
|
+
const _test = false;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('IsUnknown', () => {
|
|
65
|
+
it('should detect unknown', () => {
|
|
66
|
+
const _test = true;
|
|
67
|
+
});
|
|
68
|
+
it('should not detect string as unknown', () => {
|
|
69
|
+
const _test = false;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('IsVoid', () => {
|
|
73
|
+
it('should detect void', () => {
|
|
74
|
+
const _test = true;
|
|
75
|
+
});
|
|
76
|
+
it('should not detect string as void', () => {
|
|
77
|
+
const _test = false;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe('IsUndefined', () => {
|
|
81
|
+
it('should detect undefined', () => {
|
|
82
|
+
const _test = true;
|
|
83
|
+
});
|
|
84
|
+
it('should not detect string as undefined', () => {
|
|
85
|
+
const _test = false;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe('IsNull', () => {
|
|
89
|
+
it('should detect null', () => {
|
|
90
|
+
const _test = true;
|
|
91
|
+
});
|
|
92
|
+
it('should not detect string as null', () => {
|
|
93
|
+
const _test = false;
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('IsNullable', () => {
|
|
97
|
+
it('should detect nullable types with null', () => {
|
|
98
|
+
const _test = true;
|
|
99
|
+
});
|
|
100
|
+
it('should detect nullable types with undefined', () => {
|
|
101
|
+
const _test = true;
|
|
102
|
+
});
|
|
103
|
+
it('should detect fully nullable', () => {
|
|
104
|
+
const _test = true;
|
|
105
|
+
});
|
|
106
|
+
it('should not detect non-nullable', () => {
|
|
107
|
+
const _test = false;
|
|
108
|
+
});
|
|
109
|
+
it('should detect null as nullable', () => {
|
|
110
|
+
const _test = true;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('IsOptional', () => {
|
|
114
|
+
it('should detect optional types', () => {
|
|
115
|
+
const _test = true;
|
|
116
|
+
});
|
|
117
|
+
it('should detect required types as not optional', () => {
|
|
118
|
+
const _test = false;
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('IsUnion', () => {
|
|
122
|
+
it('should detect unions', () => {
|
|
123
|
+
const _test = true;
|
|
124
|
+
});
|
|
125
|
+
it('should detect union with never', () => {
|
|
126
|
+
const _test = false;
|
|
127
|
+
});
|
|
128
|
+
it('should not detect single type as union', () => {
|
|
129
|
+
const _test = false;
|
|
130
|
+
});
|
|
131
|
+
it('should not detect primitives as union', () => {
|
|
132
|
+
const _test = false;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('IsTuple', () => {
|
|
136
|
+
it('should detect tuples', () => {
|
|
137
|
+
const _test = true;
|
|
138
|
+
});
|
|
139
|
+
it('should detect empty tuple', () => {
|
|
140
|
+
const _test = true;
|
|
141
|
+
});
|
|
142
|
+
it('should not detect arrays as tuples', () => {
|
|
143
|
+
const _test = false;
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe('IsArray', () => {
|
|
147
|
+
it('should detect arrays', () => {
|
|
148
|
+
const _test = true;
|
|
149
|
+
});
|
|
150
|
+
it('should not detect tuples as arrays', () => {
|
|
151
|
+
const _test = false;
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('IsInhabited', () => {
|
|
155
|
+
it('should detect inhabited types', () => {
|
|
156
|
+
const _test = true;
|
|
157
|
+
});
|
|
158
|
+
it('should detect object types as inhabited', () => {
|
|
159
|
+
const _test = true;
|
|
160
|
+
});
|
|
161
|
+
it('should not detect never as inhabited', () => {
|
|
162
|
+
const _test = false;
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('IsUninhabited', () => {
|
|
166
|
+
it('should detect uninhabited types', () => {
|
|
167
|
+
const _test = true;
|
|
168
|
+
});
|
|
169
|
+
it('should not detect string as uninhabited', () => {
|
|
170
|
+
const _test = false;
|
|
171
|
+
});
|
|
172
|
+
it('should not detect any as uninhabited', () => {
|
|
173
|
+
const _test = false;
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe('HasProperty', () => {
|
|
177
|
+
it('should detect existing property', () => {
|
|
178
|
+
const _test = true;
|
|
179
|
+
});
|
|
180
|
+
it('should detect multiple properties', () => {
|
|
181
|
+
const _test = true;
|
|
182
|
+
});
|
|
183
|
+
it('should not detect missing property', () => {
|
|
184
|
+
const _test = false;
|
|
185
|
+
});
|
|
186
|
+
it('should work with optional properties', () => {
|
|
187
|
+
const _test = true;
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('PropertyType', () => {
|
|
191
|
+
it('should get property type', () => {
|
|
192
|
+
const _test = 'hello';
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
describe('Parameters', () => {
|
|
196
|
+
it('should get function parameters', () => {
|
|
197
|
+
const _test = ['hello', 42];
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('ReturnType', () => {
|
|
201
|
+
it('should get function return type', () => {
|
|
202
|
+
const _test = 42;
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('Parameter', () => {
|
|
206
|
+
it('should get parameter at index 0', () => {
|
|
207
|
+
const _test = 'hello';
|
|
208
|
+
});
|
|
209
|
+
it('should get parameter at index 1', () => {
|
|
210
|
+
const _test = 42;
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe('Length', () => {
|
|
214
|
+
it('should get array length', () => {
|
|
215
|
+
const _test = 3;
|
|
216
|
+
});
|
|
217
|
+
it('should get empty array length', () => {
|
|
218
|
+
const _test = 0;
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe('check() API', () => {
|
|
222
|
+
it('should create check interface', () => {
|
|
223
|
+
const c = check();
|
|
224
|
+
// Just verify it returns something (even undefined)
|
|
225
|
+
void c;
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
describe('assert() API', () => {
|
|
229
|
+
it('should create assert interface', () => {
|
|
230
|
+
const a = assert();
|
|
231
|
+
void a;
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
describe('expect() API', () => {
|
|
235
|
+
it('should create expect interface', () => {
|
|
236
|
+
const e = expect();
|
|
237
|
+
void e;
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
describe('SimpleEqual', () => {
|
|
241
|
+
it('should detect equal types', () => {
|
|
242
|
+
const _test = true;
|
|
243
|
+
});
|
|
244
|
+
it('should detect unequal types', () => {
|
|
245
|
+
const _test = false;
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
describe('ExpectTrue', () => {
|
|
249
|
+
it('should pass for true', () => {
|
|
250
|
+
const _test = true;
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
describe('ExpectEqual', () => {
|
|
254
|
+
it('should work with equal types', () => {
|
|
255
|
+
const _test = {};
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
describe('expectFalse', () => {
|
|
259
|
+
it('should compile for false', () => {
|
|
260
|
+
// If this compiles, expectFalse works
|
|
261
|
+
expectFalse();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sDAAsD;AAEtD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO;AACL,eAAe;AACf,KAAK,EACL,MAAM,EACN,MAAM,EACN,WAAW,GAuCZ,MAAM,SAAS,CAAA;AAEhB,uDAAuD;AACvD,kDAAkD;AAElD,QAAQ,CAA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C,0BAA0B,EAAE,GAAG,EAAE;QAClC,sCAAsC;QACtC,WAAW,EAAS,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type equality utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if two types are strictly equal.
|
|
6
|
+
* Uses a technique that compares the structure while handling
|
|
7
|
+
* special types like any, never, and unknown.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* check<string>().equals<string>() // passes
|
|
12
|
+
* check<string>().equals<number>() // fails at compile time
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type Equal<T, U> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2) ? true : false;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if two types are not equal.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* check<string>().notEquals<number>() // passes
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type NotEqual<T, U> = Equal<T, U> extends true ? false : true;
|
|
25
|
+
/**
|
|
26
|
+
* Simple equality check that works in more contexts.
|
|
27
|
+
* Useful for simple type comparisons.
|
|
28
|
+
*/
|
|
29
|
+
export type SimpleEqual<T, U> = [T, U] extends [U, T] ? true : false;
|
|
30
|
+
//# sourceMappingURL=equality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/types/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IACpB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GACjE,IAAI,GACJ,KAAK,CAAA;AAEX;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA;AAEpE;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equality.js","sourceRoot":"","sources":["../../src/types/equality.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function type utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Gets the parameters of a function type as a tuple.
|
|
6
|
+
*/
|
|
7
|
+
export type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the return type of a function type.
|
|
10
|
+
*/
|
|
11
|
+
export type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : never;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the parameter type at a specific index.
|
|
14
|
+
*/
|
|
15
|
+
export type Parameter<T extends (...args: any[]) => any, N extends number> = Parameters<T>[N];
|
|
16
|
+
//# sourceMappingURL=function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;AAE3G;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE7G;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,SAAS,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type testing utilities.
|
|
3
|
+
*/
|
|
4
|
+
export * from './equality';
|
|
5
|
+
export * from './special';
|
|
6
|
+
export * from './union';
|
|
7
|
+
export * from './inhabitation';
|
|
8
|
+
export * from './property';
|
|
9
|
+
export * from './function';
|
|
10
|
+
export * from './length';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type testing utilities.
|
|
3
|
+
*/
|
|
4
|
+
// Re-export all types
|
|
5
|
+
export * from './equality';
|
|
6
|
+
export * from './special';
|
|
7
|
+
export * from './union';
|
|
8
|
+
export * from './inhabitation';
|
|
9
|
+
export * from './property';
|
|
10
|
+
export * from './function';
|
|
11
|
+
export * from './length';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sBAAsB;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type inhabitation utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a type is inhabited (has at least one value).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* check<string>().isInhabited() // passes
|
|
10
|
+
* check<never>().isInhabited() // fails
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type IsInhabited<T> = [T] extends [never] ? false : true;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a type is uninhabited (has no values).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* check<never>().isUninhabited() // passes
|
|
20
|
+
* check<string>().isUninhabited() // fails
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type IsUninhabited<T> = [T] extends [never] ? true : false;
|
|
24
|
+
//# sourceMappingURL=inhabitation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inhabitation.d.ts","sourceRoot":"","sources":["../../src/types/inhabitation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,CAAA;AAE/D;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inhabitation.js","sourceRoot":"","sources":["../../src/types/inhabitation.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"length.d.ts","sourceRoot":"","sources":["../../src/types/length.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"length.js","sourceRoot":"","sources":["../../src/types/length.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property testing utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a type has a specific property.
|
|
6
|
+
*/
|
|
7
|
+
export type HasProperty<T, K extends PropertyKey> = K extends keyof T ? true : false;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the type of a specific property from a type.
|
|
10
|
+
*/
|
|
11
|
+
export type PropertyType<T, K extends keyof T> = T[K];
|
|
12
|
+
//# sourceMappingURL=property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../src/types/property.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAEpF;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../src/types/property.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Special type detection utilities.
|
|
3
|
+
*/
|
|
4
|
+
import type { Equal } from './equality';
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a type is `any`.
|
|
7
|
+
* Uses the technique: 0 extends (1 & T) ? true : false
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* check<any>().isAny() // passes
|
|
12
|
+
* check<string>().isAny() // fails
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type IsAny<T> = 0 extends (1 & T) ? true : false;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a type is `never`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* check<never>().isNever() // passes
|
|
22
|
+
* check<string>().isNever() // fails
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a type is `unknown`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* check<unknown>().isUnknown() // passes
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export type IsUnknown<T> = [unknown] extends [T] ? ([T] extends [unknown] ? true : false) : false;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a type is `void`.
|
|
37
|
+
*/
|
|
38
|
+
export type IsVoid<T> = Equal<T, void>;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a type is `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
export type IsUndefined<T> = Equal<T, undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a type is `null`.
|
|
45
|
+
*/
|
|
46
|
+
export type IsNull<T> = Equal<T, null>;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a type is `null` or `undefined`.
|
|
49
|
+
*/
|
|
50
|
+
export type IsNullable<T> = [null] extends [T] ? true : ([undefined] extends [T] ? true : false);
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a type is optional (may be undefined).
|
|
53
|
+
*/
|
|
54
|
+
export type IsOptional<T> = [undefined] extends [T] ? true : false;
|
|
55
|
+
//# sourceMappingURL=special.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special.d.ts","sourceRoot":"","sources":["../../src/types/special.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAEvD;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAE3D;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAA;AAEjG;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AAEhD;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,CAAA;AAEhG;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special.js","sourceRoot":"","sources":["../../src/types/special.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Union and tuple detection utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a type is a union.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* check<'a' | 'b'>().isUnion() // passes
|
|
10
|
+
* check<'a'>().isUnion() // fails
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type IsUnion<T, U = T> = [U] extends [never] ? false : T extends U ? [Exclude<U, never>] extends [T] ? false : true : false;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a type is a tuple.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* check<[string, number]>().isTuple() // passes
|
|
20
|
+
* check<string[]>().isTuple() // fails
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type IsTuple<T> = T extends readonly any[] ? (number extends T['length'] ? false : true) : false;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if a type is an array.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* check<string[]>().isArray() // passes
|
|
30
|
+
* check<[string]>().isArray() // fails
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type IsArray<T> = T extends readonly any[] ? (IsTuple<T> extends true ? false : true) : false;
|
|
34
|
+
//# sourceMappingURL=union.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/types/union.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAA;AAElI;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,EAAE,GAAG,CAAC,MAAM,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAA;AAEvG;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/types/union.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Additional utilities.
|
|
3
|
+
*/
|
|
4
|
+
import type { Equal } from './types/equality';
|
|
5
|
+
/**
|
|
6
|
+
* Type that always resolves to true.
|
|
7
|
+
* Useful for making compile-time assertions.
|
|
8
|
+
*/
|
|
9
|
+
export type ExpectTrue<_T extends true> = true;
|
|
10
|
+
/**
|
|
11
|
+
* Type that validates equality and throws if not equal.
|
|
12
|
+
*/
|
|
13
|
+
export type ExpectEqual<T, U> = Equal<T, U> extends true ? T : never;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,EAAE,SAAS,IAAI,IAAI,IAAI,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK,CAAA"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|