lay-sing 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/LICENSE +21 -21
- package/README.md +94 -79
- package/esm/main/array.d.ts +0 -0
- package/esm/main/array.d.ts.map +0 -0
- package/esm/main/array.js +0 -0
- package/esm/main/array.js.map +0 -0
- package/esm/main/async.d.ts +0 -0
- package/esm/main/async.d.ts.map +0 -0
- package/esm/main/async.js +0 -0
- package/esm/main/async.js.map +0 -0
- package/esm/main/boolean.d.ts +0 -0
- package/esm/main/boolean.d.ts.map +0 -0
- package/esm/main/boolean.js +0 -0
- package/esm/main/boolean.js.map +0 -0
- package/esm/main/control.d.ts +0 -0
- package/esm/main/control.d.ts.map +0 -0
- package/esm/main/control.js +0 -0
- package/esm/main/control.js.map +0 -0
- package/esm/main/doc.d.ts +0 -0
- package/esm/main/doc.d.ts.map +0 -0
- package/esm/main/doc.js +0 -0
- package/esm/main/doc.js.map +0 -0
- package/esm/main/function.d.ts +0 -0
- package/esm/main/function.d.ts.map +0 -0
- package/esm/main/function.js +0 -0
- package/esm/main/function.js.map +0 -0
- package/esm/main/index.d.ts +0 -0
- package/esm/main/index.d.ts.map +0 -0
- package/esm/main/index.js +0 -0
- package/esm/main/index.js.map +0 -0
- package/esm/main/json.d.ts +0 -0
- package/esm/main/json.d.ts.map +0 -0
- package/esm/main/json.js +0 -0
- package/esm/main/json.js.map +0 -0
- package/esm/main/key.d.ts +0 -0
- package/esm/main/key.d.ts.map +0 -0
- package/esm/main/key.js +0 -0
- package/esm/main/key.js.map +0 -0
- package/esm/main/object.d.ts +0 -0
- package/esm/main/object.d.ts.map +0 -0
- package/esm/main/object.js +0 -0
- package/esm/main/object.js.map +0 -0
- package/esm/main/type/compare.d.ts +0 -0
- package/esm/main/type/compare.d.ts.map +0 -0
- package/esm/main/type/compare.js +0 -0
- package/esm/main/type/compare.js.map +0 -0
- package/esm/main/type/index.d.ts +0 -0
- package/esm/main/type/index.d.ts.map +0 -0
- package/esm/main/type/index.js +0 -0
- package/esm/main/type/index.js.map +0 -0
- package/esm/main/type/set.d.ts +0 -0
- package/esm/main/type/set.d.ts.map +0 -0
- package/esm/main/type/set.js +0 -0
- package/esm/main/type/set.js.map +0 -0
- package/esm/main/typed-array.d.ts +0 -0
- package/esm/main/typed-array.d.ts.map +0 -0
- package/esm/main/typed-array.js +0 -0
- package/esm/main/typed-array.js.map +0 -0
- package/esm/package.json +0 -0
- package/esm/test-utils.d.ts +0 -0
- package/esm/test-utils.d.ts.map +1 -1
- package/esm/test-utils.js +8 -0
- package/esm/test-utils.js.map +1 -1
- package/package.json +2 -2
- package/script/main/array.d.ts +0 -0
- package/script/main/array.d.ts.map +0 -0
- package/script/main/array.js +0 -0
- package/script/main/array.js.map +0 -0
- package/script/main/async.d.ts +0 -0
- package/script/main/async.d.ts.map +0 -0
- package/script/main/async.js +0 -0
- package/script/main/async.js.map +0 -0
- package/script/main/boolean.d.ts +0 -0
- package/script/main/boolean.d.ts.map +0 -0
- package/script/main/boolean.js +0 -0
- package/script/main/boolean.js.map +0 -0
- package/script/main/control.d.ts +0 -0
- package/script/main/control.d.ts.map +0 -0
- package/script/main/control.js +0 -0
- package/script/main/control.js.map +0 -0
- package/script/main/doc.d.ts +0 -0
- package/script/main/doc.d.ts.map +0 -0
- package/script/main/doc.js +0 -0
- package/script/main/doc.js.map +0 -0
- package/script/main/function.d.ts +0 -0
- package/script/main/function.d.ts.map +0 -0
- package/script/main/function.js +0 -0
- package/script/main/function.js.map +0 -0
- package/script/main/index.d.ts +0 -0
- package/script/main/index.d.ts.map +0 -0
- package/script/main/index.js +0 -0
- package/script/main/index.js.map +0 -0
- package/script/main/json.d.ts +0 -0
- package/script/main/json.d.ts.map +0 -0
- package/script/main/json.js +0 -0
- package/script/main/json.js.map +0 -0
- package/script/main/key.d.ts +0 -0
- package/script/main/key.d.ts.map +0 -0
- package/script/main/key.js +0 -0
- package/script/main/key.js.map +0 -0
- package/script/main/object.d.ts +0 -0
- package/script/main/object.d.ts.map +0 -0
- package/script/main/object.js +0 -0
- package/script/main/object.js.map +0 -0
- package/script/main/type/compare.d.ts +0 -0
- package/script/main/type/compare.d.ts.map +0 -0
- package/script/main/type/compare.js +0 -0
- package/script/main/type/compare.js.map +0 -0
- package/script/main/type/index.d.ts +0 -0
- package/script/main/type/index.d.ts.map +0 -0
- package/script/main/type/index.js +0 -0
- package/script/main/type/index.js.map +0 -0
- package/script/main/type/set.d.ts +0 -0
- package/script/main/type/set.d.ts.map +0 -0
- package/script/main/type/set.js +0 -0
- package/script/main/type/set.js.map +0 -0
- package/script/main/typed-array.d.ts +0 -0
- package/script/main/typed-array.d.ts.map +0 -0
- package/script/main/typed-array.js +0 -0
- package/script/main/typed-array.js.map +0 -0
- package/script/package.json +0 -0
- package/script/test-utils.d.ts +0 -0
- package/script/test-utils.d.ts.map +1 -1
- package/script/test-utils.js +8 -0
- package/script/test-utils.js.map +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Leawind <leawind@yeah.net>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Leawind <leawind@yeah.net>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
| English | [简体中文](./README-zh.md) |
|
|
2
2
|
| ------- | -------------------------- |
|
|
3
|
-
| | |
|
|
4
3
|
|
|
5
4
|
# `lay-sing`
|
|
6
5
|
|
|
7
|
-
TypeScript utilities for compile-time type
|
|
6
|
+
TypeScript utilities for compile-time type testing and utility types
|
|
8
7
|
|
|
9
8
|
## What is it
|
|
10
9
|
|
|
@@ -12,14 +11,16 @@ TypeScript utilities for compile-time type validation and testing
|
|
|
12
11
|
|
|
13
12
|
```ts
|
|
14
13
|
// They do nothing at runtime
|
|
15
|
-
expect<
|
|
16
|
-
expect<
|
|
14
|
+
expect<never>().toBe<never>().success
|
|
15
|
+
expect<never>().toBeNever // alias for above
|
|
16
|
+
expect<never>().toBe<'should fail'>().fail
|
|
17
17
|
|
|
18
|
-
// Type
|
|
19
|
-
expect<
|
|
18
|
+
// Type Error: Property 'success' does not exist on type '{ fail: void; }'.
|
|
19
|
+
expect<never>().toBe<'should fail'>().success
|
|
20
|
+
// ^^^^^^^
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
1. **Type Manipulation Tools**
|
|
23
24
|
|
|
24
25
|
```ts
|
|
25
26
|
// Result is 'Bob'
|
|
@@ -32,78 +33,94 @@ type Result = Switch<2, [
|
|
|
32
33
|
|
|
33
34
|
## Install
|
|
34
35
|
|
|
35
|
-
(
|
|
36
|
+
> This lib is published to both [NPM](https://www.npmjs.com/package/lay-sing) and [JSR](https://jsr.io/@leawind/lay-sing)
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
### NPM
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
```sh
|
|
41
|
+
npm i -D lay-sing
|
|
42
|
+
```
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
```ts
|
|
45
|
+
import type { Same } from 'lay-sing'
|
|
46
|
+
import { expect } from 'lay-sing/test-utils'
|
|
47
|
+
```
|
|
42
48
|
|
|
43
|
-
|
|
49
|
+
### Deno (JSR)
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
deno add jsr:@leawind/lay-sing
|
|
53
|
+
```
|
|
44
54
|
|
|
45
55
|
```ts
|
|
46
|
-
|
|
47
|
-
expect
|
|
48
|
-
|
|
56
|
+
import type { Same } from '@leawind/lay-sing'
|
|
57
|
+
import { expect } from '@leawind/lay-sing/test-utils'
|
|
58
|
+
```
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
expect<2>().toExtend<number>().success
|
|
52
|
-
expect<2>().toExtend<string>().fail
|
|
60
|
+
Or Import directly:
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
```ts
|
|
63
|
+
import type { Same } from 'jsr:@leawind/lay-sing@^0.1'
|
|
64
|
+
import { expect } from 'jsr:@leawind/lay-sing@^0.1/test-utils'
|
|
65
|
+
```
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
### Testing Utilities
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { compare, expect, NOOP } from 'lay-sing/test-utils'
|
|
60
75
|
```
|
|
61
76
|
|
|
62
|
-
|
|
77
|
+
The `test-utils` module provides utilities for **compile-time** type validation. These utilities have **no runtime effect** — they always return a special [`NOOP`](https://jsr.io/@leawind/lay-sing/doc/test-utils/~/NOOP) value that safely supports almost any property access or method call.
|
|
78
|
+
|
|
79
|
+
A typical type test statement follows this pattern:
|
|
63
80
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
- `toHaveProperty<K>()` - Tests if type has a property with key K
|
|
68
|
-
- `toExtendNumber` - Tests if type extends the Number primitive (available only when type extends number)
|
|
69
|
-
- `toExtendString` - Tests if type extends the String primitive (available only when type extends string)
|
|
70
|
-
- `toExtendBoolean` - Tests if type extends the Boolean primitive (available only when type extends boolean)
|
|
71
|
-
- Specific primitive type checks: `toBeAny`, `toBeNever`, `toBeUnknown`, `toBeVoid`, `toBeTrue`, `toBeFalse`
|
|
81
|
+
```ts
|
|
82
|
+
expect<ActualType>().toBe<ExpectedType>().success
|
|
83
|
+
```
|
|
72
84
|
|
|
73
|
-
|
|
85
|
+
- It starts with a function call like `expect<T>()` or `compare<T, U>()`
|
|
86
|
+
- It ends with a property like `.success` or `.fail`
|
|
87
|
+
- A **type error occurs only if the assertion fails**, helping you catch incorrect types at compile time
|
|
88
|
+
- At runtime, the function always returns the actual value `NOOP`, which performs **no operation**. It can be accessed, called, or chained indefinitely without throwing
|
|
74
89
|
|
|
75
|
-
|
|
90
|
+
#### Common Usage
|
|
76
91
|
|
|
77
92
|
```ts
|
|
78
|
-
//
|
|
79
|
-
|
|
93
|
+
// Exact equality
|
|
94
|
+
expect<A>().toBe<B>().success // Passes only if A and B are identical
|
|
80
95
|
|
|
81
|
-
//
|
|
82
|
-
|
|
96
|
+
// Subtype check
|
|
97
|
+
expect<A>().toExtend<B>().success // Passes if A extends B
|
|
83
98
|
|
|
84
|
-
//
|
|
85
|
-
|
|
99
|
+
// Property existence
|
|
100
|
+
expect<{ name: string }>().toHaveProperty<'name'>().success
|
|
86
101
|
|
|
87
|
-
//
|
|
88
|
-
|
|
102
|
+
// Primitive checks
|
|
103
|
+
expect<true>().toBeTrue.success
|
|
104
|
+
expect<'hello'>().toExtendString.success
|
|
89
105
|
|
|
90
|
-
//
|
|
91
|
-
compare<
|
|
106
|
+
// Type comparison
|
|
107
|
+
compare<A, B>().same // Available only if A ≡ B
|
|
108
|
+
compare<A, B>().different // Available only if A ≠ B
|
|
92
109
|
```
|
|
93
110
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
- `disjoint` - Available when types have no overlap
|
|
100
|
-
- `mutuallyAssignable` - Available when types are mutually assignable
|
|
111
|
+
> [!TIP]
|
|
112
|
+
>
|
|
113
|
+
> There's no need to memorize the full API.
|
|
114
|
+
>
|
|
115
|
+
> Your editor will show inline documentation and auto-completion for all available methods and properties
|
|
101
116
|
|
|
102
|
-
|
|
117
|
+
#### NOOP
|
|
103
118
|
|
|
104
|
-
|
|
119
|
+
A `Proxy`-based no-op object:
|
|
105
120
|
|
|
106
|
-
|
|
121
|
+
- Most accesses return itself.
|
|
122
|
+
- `toString()` returns `"[NOOP]"`.
|
|
123
|
+
- Not thenable (`then` is `undefined`).
|
|
107
124
|
|
|
108
125
|
```ts
|
|
109
126
|
NOOP.foo.bar().baz.qux // safe, returns NOOP
|
|
@@ -111,41 +128,39 @@ String(NOOP) // "[NOOP]"
|
|
|
111
128
|
await NOOP // does not await (not thenable)
|
|
112
129
|
```
|
|
113
130
|
|
|
114
|
-
|
|
131
|
+
### Type Tools
|
|
115
132
|
|
|
116
|
-
|
|
133
|
+
The main entry point provides a collection of utility types for common type-level programming tasks. All types are flat-exported from the main entry point — you don’t need to import from deep paths.
|
|
117
134
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
type Result = If<true, 'yes', 'no'> // 'yes'
|
|
122
|
-
type Conditional = If<boolean, 'yes', 'no'> // 'yes' | 'no'
|
|
135
|
+
```ts
|
|
136
|
+
import type { Same } from 'lay-sing'
|
|
123
137
|
```
|
|
124
138
|
|
|
125
|
-
|
|
139
|
+
> All types are documented — your editor will show inline documentation on hover
|
|
140
|
+
|
|
141
|
+
### Examples
|
|
126
142
|
|
|
127
143
|
```typescript
|
|
128
|
-
|
|
129
|
-
type
|
|
130
|
-
type Either = Or<true, false> // true
|
|
131
|
-
type Negation = Not<true> // false
|
|
132
|
-
```
|
|
144
|
+
// Conditional Types
|
|
145
|
+
type Result = If<true, 'yes', 'no'> // 'yes'
|
|
133
146
|
|
|
134
|
-
|
|
147
|
+
// Boolean Logic
|
|
148
|
+
type IsTrue = And<true, true> // true
|
|
135
149
|
|
|
136
|
-
|
|
150
|
+
// Tuple Manipulation
|
|
137
151
|
type Combined = ConcatTuple<[1, 2], [3, 4]> // [1, 2, 3, 4]
|
|
138
|
-
type UniqueCombined = ConcatUniqueTuple<[1, 2, 3], [2, 3, 4]> // [1, 2, 3, 4]
|
|
139
|
-
type HasElement = TupleIncludes<[1, 2, 3], 2> // true
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Object Manipulation
|
|
143
152
|
|
|
144
|
-
|
|
145
|
-
type PartialObj = DeepPartial<{ a: string; nested: { b: number } }>
|
|
146
|
-
|
|
153
|
+
// Object Utilities
|
|
154
|
+
type PartialObj = DeepPartial<{ a: string; nested: { b: number } }>
|
|
155
|
+
// { a?: string; nested?: { b?: number } }
|
|
147
156
|
```
|
|
148
157
|
|
|
149
|
-
|
|
158
|
+
> [!NOTE]
|
|
159
|
+
>
|
|
160
|
+
> [Full API documentation is available on JSR](https://jsr.io/@leawind/lay-sing/doc)
|
|
161
|
+
|
|
162
|
+
---
|
|
150
163
|
|
|
151
|
-
|
|
164
|
+
> ## _Pronunciation of lay-sing_
|
|
165
|
+
>
|
|
166
|
+
> _"lay-sing" mimics Mandarin "lèi xíng" ("type") — Say "LAY-sing" with a sharp "LAY" (like a command) followed by a rising "sing" (like a question)._
|
package/esm/main/array.d.ts
CHANGED
|
File without changes
|
package/esm/main/array.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/array.js
CHANGED
|
File without changes
|
package/esm/main/array.js.map
CHANGED
|
File without changes
|
package/esm/main/async.d.ts
CHANGED
|
File without changes
|
package/esm/main/async.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/async.js
CHANGED
|
File without changes
|
package/esm/main/async.js.map
CHANGED
|
File without changes
|
package/esm/main/boolean.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/boolean.js
CHANGED
|
File without changes
|
package/esm/main/boolean.js.map
CHANGED
|
File without changes
|
package/esm/main/control.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/control.js
CHANGED
|
File without changes
|
package/esm/main/control.js.map
CHANGED
|
File without changes
|
package/esm/main/doc.d.ts
CHANGED
|
File without changes
|
package/esm/main/doc.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/doc.js
CHANGED
|
File without changes
|
package/esm/main/doc.js.map
CHANGED
|
File without changes
|
package/esm/main/function.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/function.js
CHANGED
|
File without changes
|
package/esm/main/function.js.map
CHANGED
|
File without changes
|
package/esm/main/index.d.ts
CHANGED
|
File without changes
|
package/esm/main/index.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/index.js
CHANGED
|
File without changes
|
package/esm/main/index.js.map
CHANGED
|
File without changes
|
package/esm/main/json.d.ts
CHANGED
|
File without changes
|
package/esm/main/json.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/json.js
CHANGED
|
File without changes
|
package/esm/main/json.js.map
CHANGED
|
File without changes
|
package/esm/main/key.d.ts
CHANGED
|
File without changes
|
package/esm/main/key.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/key.js
CHANGED
|
File without changes
|
package/esm/main/key.js.map
CHANGED
|
File without changes
|
package/esm/main/object.d.ts
CHANGED
|
File without changes
|
package/esm/main/object.d.ts.map
CHANGED
|
File without changes
|
package/esm/main/object.js
CHANGED
|
File without changes
|
package/esm/main/object.js.map
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/esm/main/type/compare.js
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/type/index.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/type/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/type/set.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/main/type/set.js
CHANGED
|
File without changes
|
package/esm/main/type/set.js.map
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/esm/main/typed-array.js
CHANGED
|
File without changes
|
|
File without changes
|
package/esm/package.json
CHANGED
|
File without changes
|
package/esm/test-utils.d.ts
CHANGED
|
File without changes
|
package/esm/test-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,EAAE,EACF,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACL,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,EAAE,EACF,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACL,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,EAAE,GA0BlB,CAAA;AAED;;;;;;GAMG;AACH,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,IAAI,GAAG;IAC7D;;OAEG;IACH,OAAO,EAAE,CAAC,CAAA;CACX,GACC;IACA;;OAEG;IACH,IAAI,EAAE,CAAC,CAAA;CACR,CAAA;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,KAAK,IAAI,IAAI,CAC7D,CACI;IACA,CAAC,EAAE,CAAC,CAAA;IACJ,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAAE,CAAA;IAEjC;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAE7B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,CAAC,KA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
|
|
42
|
+
set: () => true,
|
|
43
|
+
getOwnPropertyDescriptor: () => ({
|
|
44
|
+
configurable: true,
|
|
45
|
+
value: NOOP,
|
|
46
|
+
}),
|
|
47
|
+
getPrototypeOf: () => null,
|
|
48
|
+
has: () => true,
|
|
49
|
+
ownKeys: () => ['prototype'],
|
|
42
50
|
});
|
|
43
51
|
export function expect() {
|
|
44
52
|
return NOOP;
|
package/esm/test-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAQ,IAAI,KAAK,CAChC;IACE,OAAO,IAAI,CAAA;AACb,CAAC,EACD;IACE,GAAG,CAAC,CAAC,EAAE,IAAI;QACT,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACT,OAAO,SAAS,CAAA;YAClB,KAAK,SAAS,CAAC;YACf,KAAK,UAAU,CAAC;YAChB,KAAK,MAAM,CAAC,WAAW;gBACrB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAA;YACvB;gBACE,OAAO,IAAI,CAAA;QACf,CAAC;IACH,CAAC;CACF,CACF,CAAA;AAkQD,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,CAAA;AACb,CAAC;AA+GD,MAAM,UAAU,OAAO;IACrB,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["// deno-lint-ignore-file no-explicit-any\nimport type {\n Diff,\n Disjoint,\n Extends,\n If,\n MutuallyAssignable,\n Overlap,\n ProperExtend,\n SafePick,\n Same,\n} from './main/index.js'\n\n/**\n * A universal no-op placeholder implemented via `Proxy`.\n *\n * `NOOP` can be accessed, called, or chained indefinitely without throwing.\n * Every operation returns itself, making it safe to use as a dummy fallback\n * for APIs, optional hooks, or unimplemented interfaces.\n *\n * ### Special behaviors\n *\n * - Callable: invoking `NOOP()` returns `NOOP`\n * - Property access: `NOOP.anything` returns `NOOP`\n * - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise\n * - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields\n * a stable string representation: `\"[NOOP]\"`\n *\n * This is useful in scenarios where a value is required syntactically but\n * should perform no action and never fail at runtime.\n *\n * ### Examples\n *\n * ```ts\n * NOOP.foo.bar().baz.qux; // safe, returns NOOP\n * String(NOOP); // \"[NOOP]\"\n * await NOOP; // does not await (not thenable)\n * ```\n */\nexport const NOOP: any = new Proxy(\n function () {\n return NOOP\n },\n {\n get(_, prop) {\n switch (prop) {\n case 'then':\n return undefined\n case 'valueOf':\n case 'toString':\n case Symbol.toPrimitive:\n return () => '[NOOP]'\n default:\n return NOOP\n }\n },\n },\n)\n\n/**\n * Represents the result of a type assertion based on a boolean condition.\n * If the condition is true, the result has a `success` property; otherwise, it has a `fail` property.\n *\n * @template B The boolean condition result (true or false)\n * @template R The type of the result value (default is void)\n */\ntype Result<B extends true | false, R = void> = B extends true ? {\n /**\n * ## Expect to succeed without type error\n */\n success: R\n }\n : {\n /**\n * ## Expect to fail with type error\n */\n fail: R\n }\n\n/**\n * Type-level testing utility that allows checking various relationships between types.\n * Provides methods to test type equality, extension, properties, and more.\n *\n * @template T The type being tested\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Test if two types are identical\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<2>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * // Test if type has a specific property\n * expect<{name: string}>().toHaveProperty<'name'>().success\n * ```\n */\nexport type ExpectType<T, H extends PropertyKey = never> = Omit<\n (\n & {\n T: T\n inspect: { [K in keyof T]: T[K] }\n\n /**\n * Tests if the current type is exactly the same as the provided type U.\n *\n * @template U The type to compare with\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBe<any>().success\n * expect<never>().toBe<never>().success\n * expect<false>().toBe<true>().fail\n * ```\n */\n toBe<U>(): Result<Same<T, U>>\n\n /**\n * Tests if the current type T extends the provided type U.\n *\n * @template U The type to check extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * expect<'hello'>().toExtend<string>().success\n * ```\n */\n toExtend<U>(): Result<Extends<T, U>>\n\n /**\n * Tests if the current type T properly extends the provided type U (extends but is not the same).\n *\n * @template U The type to check proper extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<2>().toProperExtend<number>().success\n * expect<'a' | 'b'>().toProperExtend<string>().success\n * expect<number>().toProperExtend<number>().fail\n * ```\n */\n toProperExtend<U>(): Result<ProperExtend<T, U>>\n\n /**\n * Tests if the current type T has a property with key K.\n *\n * @template K The property key to check for\n *\n * ### Examples\n *\n * ```ts\n * type WithProp = { prop: string; another: number }\n * expect<WithProp>().toHaveProperty<'prop'>().success\n * expect<WithProp>().toHaveProperty<'another'>().success\n * expect<WithProp>().toHaveProperty<'missing'>().fail\n * ```\n */\n toHaveProperty<K extends PropertyKey>(): Result<Extends<K, keyof T>>\n }\n & SafePick<\n {\n /**\n * Tests if the current type extends the Number primitive type.\n * Available only if the current type extends number.\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtendNumber // Available and would succeed\n * ```\n */\n toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>\n\n /**\n * Tests if the current type extends the String primitive type.\n * Available only if the current type extends string.\n *\n * ### Examples\n *\n * ```ts\n * expect<'hello'>().toExtendString // Available and would succeed\n * ```\n */\n toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>\n\n /**\n * Tests if the current type extends the Boolean primitive type.\n * Available only if the current type extends boolean.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toExtendBoolean // Available and would succeed\n * ```\n */\n toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>\n },\n | If<Extends<T, number>, 'toExtendNumber'>\n | If<Extends<T, string>, 'toExtendString'>\n | If<Extends<T, boolean>, 'toExtendBoolean'>\n >\n & SafePick<\n {\n /**\n * Tests if the current type is exactly `any`.\n * Available only if the current type is `any`.\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBeAny // Available and would succeed\n * ```\n */\n toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `never`.\n * Available only if the current type is `never`.\n *\n * ### Examples\n *\n * ```ts\n * expect<never>().toBeNever // Available and would succeed\n * ```\n */\n toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `unknown`.\n * Available only if the current type is `unknown`.\n *\n * ### Examples\n *\n * ```ts\n * expect<unknown>().toBeUnknown // Available and would succeed\n * ```\n */\n toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `void`.\n * Available only if the current type is `void`.\n *\n * ### Examples\n *\n * ```ts\n * expect<void>().toBeVoid // Available and would succeed\n * ```\n */\n toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `true` (boolean literal).\n * Available only if the current type is `true`.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toBeTrue // Available and would succeed\n * ```\n */\n toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>\n\n /**\n * Tests if the current type is exactly `false` (boolean literal).\n * Available only if the current type is `false`.\n *\n * ### Examples\n *\n * ```ts\n * expect<false>().toBeFalse // Available and would succeed\n * ```\n */\n toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>\n },\n | If<Same<T, any>, 'toBeAny'>\n | If<Same<T, never>, 'toBeNever'>\n | If<Same<T, unknown>, 'toBeUnknown'>\n | If<Same<T, void>, 'toBeVoid'>\n | If<Same<T, true>, 'toBeTrue'>\n | If<Same<T, false>, 'toBeFalse'>\n >\n ),\n H\n>\n\n/**\n * Creates an instance of ExpectType to perform type-level assertions on the given type.\n * This function enables testing various type relationships at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T The type to be tested\n *\n * @returns An ExpectType instance with methods to test type relationships\n *\n * ### Examples\n *\n * ```ts\n * // Test exact type equality\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * ```\n */\nexport function expect<T>(): ExpectType<T>\nexport function expect<T>(_: T): ExpectType<T>\nexport function expect<T>(): ExpectType<T> {\n return NOOP\n}\n\n/**\n * Type-level utility that compares two types and provides methods to test their relationship.\n * Offers options to check if types are same, different, overlapping, disjoint, or mutually assignable.\n *\n * @template T First type to compare\n * @template U Second type to compare\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Check if two types are the same\n * compare<number, number>().same // Available\n * // Check if two types are different\n * compare<number, string>().different // Available\n * // Check if two types overlap\n * compare<4, number>().overlap.different // Available\n * ```\n */\nexport type CompareTypes<T, U, H extends PropertyKey = never> = Omit<\n SafePick<\n {\n /**\n * Available when types T and U are exactly the same.\n *\n * ### Examples\n *\n * ```ts\n * compare<3, 3>().same // Available\n * compare<boolean, boolean>().same // Available\n * ```\n */\n same: CompareTypes<T, U, H | 'same'>\n\n /**\n * Available when types T and U are different.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different // Available\n * compare<number, 4>().different // Available\n * ```\n */\n different: CompareTypes<T, U, H | 'different'>\n\n /**\n * Available when types T and U have some overlap.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, number>().overlap // Available since 4 overlaps with number\n * ```\n */\n overlap: CompareTypes<T, U, H | 'overlap'>\n\n /**\n * Available when types T and U have no overlap (are disjoint).\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different.disjoint // Available since 4 and 'abc' are disjoint\n * ```\n */\n disjoint: CompareTypes<T, U, H | 'disjoint'>\n\n /**\n * Available when types T and U are mutually assignable (each type can be assigned to the other).\n *\n * ### Examples\n *\n * ```ts\n * compare<1 | 2, 1 | 2>().mutuallyAssignable // Available since identical union types are mutually assignable\n * ```\n */\n mutuallyAssignable: CompareTypes<T, U, H | 'mutuallyAssignable'>\n },\n | If<Same<T, U>, 'same'>\n | If<Diff<T, U>, 'different'>\n | If<Overlap<T, U>, 'overlap'>\n | If<Disjoint<T, U>, 'disjoint'>\n | If<MutuallyAssignable<T, U>, 'mutuallyAssignable'>\n >,\n H\n>\n\n/**\n * Creates an instance of CompareTypes to perform type-level comparisons between two types.\n * This function enables testing various relationships between types at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T First type to compare\n * @template U Second type to compare\n *\n * @returns A CompareTypes instance with methods to test relationships between T and U\n *\n * ### Examples\n *\n * ```ts\n * // Compare two identical types\n * compare<number, number>().same // Results in an available property\n * // Compare two different but overlapping types\n * compare<4, number>().overlap.different // Results in available properties\n * ```\n */\nexport function compare<T, U>(): CompareTypes<T, U>\nexport function compare<T, U>(t: T, u: U): CompareTypes<T, U>\nexport function compare<T, U>(): CompareTypes<T, U> {\n return NOOP\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAQ,IAAI,KAAK,CAChC;IACE,OAAO,IAAI,CAAA;AACb,CAAC,EACD;IACE,GAAG,CAAC,CAAC,EAAE,IAAI;QACT,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACT,OAAO,SAAS,CAAA;YAClB,KAAK,SAAS,CAAC;YACf,KAAK,UAAU,CAAC;YAChB,KAAK,MAAM,CAAC,WAAW;gBACrB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAA;YACvB;gBACE,OAAO,IAAI,CAAA;QACf,CAAC;IACH,CAAC;IACD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;IACf,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/B,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,IAAI;KACZ,CAAC;IACF,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;IAC1B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;IACf,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC;CAC7B,CACF,CAAA;AAkQD,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,CAAA;AACb,CAAC;AA+GD,MAAM,UAAU,OAAO;IACrB,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["// deno-lint-ignore-file no-explicit-any\nimport type {\n Diff,\n Disjoint,\n Extends,\n If,\n MutuallyAssignable,\n Overlap,\n ProperExtend,\n SafePick,\n Same,\n} from './main/index.js'\n\n/**\n * A universal no-op placeholder implemented via `Proxy`.\n *\n * `NOOP` can be accessed, called, or chained indefinitely without throwing.\n * Every operation returns itself, making it safe to use as a dummy fallback\n * for APIs, optional hooks, or unimplemented interfaces.\n *\n * ### Special behaviors\n *\n * - Callable: invoking `NOOP()` returns `NOOP`\n * - Property access: `NOOP.anything` returns `NOOP`\n * - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise\n * - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields\n * a stable string representation: `\"[NOOP]\"`\n *\n * This is useful in scenarios where a value is required syntactically but\n * should perform no action and never fail at runtime.\n *\n * ### Examples\n *\n * ```ts\n * NOOP.foo.bar().baz.qux; // safe, returns NOOP\n * String(NOOP); // \"[NOOP]\"\n * await NOOP; // does not await (not thenable)\n * ```\n */\nexport const NOOP: any = new Proxy(\n function () {\n return NOOP\n },\n {\n get(_, prop) {\n switch (prop) {\n case 'then':\n return undefined\n case 'valueOf':\n case 'toString':\n case Symbol.toPrimitive:\n return () => '[NOOP]'\n default:\n return NOOP\n }\n },\n set: () => true,\n getOwnPropertyDescriptor: () => ({\n configurable: true,\n value: NOOP,\n }),\n getPrototypeOf: () => null,\n has: () => true,\n ownKeys: () => ['prototype'],\n },\n)\n\n/**\n * Represents the result of a type assertion based on a boolean condition.\n * If the condition is true, the result has a `success` property; otherwise, it has a `fail` property.\n *\n * @template B The boolean condition result (true or false)\n * @template R The type of the result value (default is void)\n */\ntype Result<B extends true | false, R = void> = B extends true ? {\n /**\n * ## Expect to succeed without type error\n */\n success: R\n }\n : {\n /**\n * ## Expect to fail with type error\n */\n fail: R\n }\n\n/**\n * Type-level testing utility that allows checking various relationships between types.\n * Provides methods to test type equality, extension, properties, and more.\n *\n * @template T The type being tested\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Test if two types are identical\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<2>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * // Test if type has a specific property\n * expect<{name: string}>().toHaveProperty<'name'>().success\n * ```\n */\nexport type ExpectType<T, H extends PropertyKey = never> = Omit<\n (\n & {\n T: T\n inspect: { [K in keyof T]: T[K] }\n\n /**\n * Tests if the current type is exactly the same as the provided type U.\n *\n * @template U The type to compare with\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBe<any>().success\n * expect<never>().toBe<never>().success\n * expect<false>().toBe<true>().fail\n * ```\n */\n toBe<U>(): Result<Same<T, U>>\n\n /**\n * Tests if the current type T extends the provided type U.\n *\n * @template U The type to check extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * expect<'hello'>().toExtend<string>().success\n * ```\n */\n toExtend<U>(): Result<Extends<T, U>>\n\n /**\n * Tests if the current type T properly extends the provided type U (extends but is not the same).\n *\n * @template U The type to check proper extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<2>().toProperExtend<number>().success\n * expect<'a' | 'b'>().toProperExtend<string>().success\n * expect<number>().toProperExtend<number>().fail\n * ```\n */\n toProperExtend<U>(): Result<ProperExtend<T, U>>\n\n /**\n * Tests if the current type T has a property with key K.\n *\n * @template K The property key to check for\n *\n * ### Examples\n *\n * ```ts\n * type WithProp = { prop: string; another: number }\n * expect<WithProp>().toHaveProperty<'prop'>().success\n * expect<WithProp>().toHaveProperty<'another'>().success\n * expect<WithProp>().toHaveProperty<'missing'>().fail\n * ```\n */\n toHaveProperty<K extends PropertyKey>(): Result<Extends<K, keyof T>>\n }\n & SafePick<\n {\n /**\n * Tests if the current type extends the Number primitive type.\n * Available only if the current type extends number.\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtendNumber // Available and would succeed\n * ```\n */\n toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>\n\n /**\n * Tests if the current type extends the String primitive type.\n * Available only if the current type extends string.\n *\n * ### Examples\n *\n * ```ts\n * expect<'hello'>().toExtendString // Available and would succeed\n * ```\n */\n toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>\n\n /**\n * Tests if the current type extends the Boolean primitive type.\n * Available only if the current type extends boolean.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toExtendBoolean // Available and would succeed\n * ```\n */\n toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>\n },\n | If<Extends<T, number>, 'toExtendNumber'>\n | If<Extends<T, string>, 'toExtendString'>\n | If<Extends<T, boolean>, 'toExtendBoolean'>\n >\n & SafePick<\n {\n /**\n * Tests if the current type is exactly `any`.\n * Available only if the current type is `any`.\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBeAny // Available and would succeed\n * ```\n */\n toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `never`.\n * Available only if the current type is `never`.\n *\n * ### Examples\n *\n * ```ts\n * expect<never>().toBeNever // Available and would succeed\n * ```\n */\n toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `unknown`.\n * Available only if the current type is `unknown`.\n *\n * ### Examples\n *\n * ```ts\n * expect<unknown>().toBeUnknown // Available and would succeed\n * ```\n */\n toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `void`.\n * Available only if the current type is `void`.\n *\n * ### Examples\n *\n * ```ts\n * expect<void>().toBeVoid // Available and would succeed\n * ```\n */\n toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `true` (boolean literal).\n * Available only if the current type is `true`.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toBeTrue // Available and would succeed\n * ```\n */\n toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>\n\n /**\n * Tests if the current type is exactly `false` (boolean literal).\n * Available only if the current type is `false`.\n *\n * ### Examples\n *\n * ```ts\n * expect<false>().toBeFalse // Available and would succeed\n * ```\n */\n toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>\n },\n | If<Same<T, any>, 'toBeAny'>\n | If<Same<T, never>, 'toBeNever'>\n | If<Same<T, unknown>, 'toBeUnknown'>\n | If<Same<T, void>, 'toBeVoid'>\n | If<Same<T, true>, 'toBeTrue'>\n | If<Same<T, false>, 'toBeFalse'>\n >\n ),\n H\n>\n\n/**\n * Creates an instance of ExpectType to perform type-level assertions on the given type.\n * This function enables testing various type relationships at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T The type to be tested\n *\n * @returns An ExpectType instance with methods to test type relationships\n *\n * ### Examples\n *\n * ```ts\n * // Test exact type equality\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * ```\n */\nexport function expect<T>(): ExpectType<T>\nexport function expect<T>(_: T): ExpectType<T>\nexport function expect<T>(): ExpectType<T> {\n return NOOP\n}\n\n/**\n * Type-level utility that compares two types and provides methods to test their relationship.\n * Offers options to check if types are same, different, overlapping, disjoint, or mutually assignable.\n *\n * @template T First type to compare\n * @template U Second type to compare\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Check if two types are the same\n * compare<number, number>().same // Available\n * // Check if two types are different\n * compare<number, string>().different // Available\n * // Check if two types overlap\n * compare<4, number>().overlap.different // Available\n * ```\n */\nexport type CompareTypes<T, U, H extends PropertyKey = never> = Omit<\n SafePick<\n {\n /**\n * Available when types T and U are exactly the same.\n *\n * ### Examples\n *\n * ```ts\n * compare<3, 3>().same // Available\n * compare<boolean, boolean>().same // Available\n * ```\n */\n same: CompareTypes<T, U, H | 'same'>\n\n /**\n * Available when types T and U are different.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different // Available\n * compare<number, 4>().different // Available\n * ```\n */\n different: CompareTypes<T, U, H | 'different'>\n\n /**\n * Available when types T and U have some overlap.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, number>().overlap // Available since 4 overlaps with number\n * ```\n */\n overlap: CompareTypes<T, U, H | 'overlap'>\n\n /**\n * Available when types T and U have no overlap (are disjoint).\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different.disjoint // Available since 4 and 'abc' are disjoint\n * ```\n */\n disjoint: CompareTypes<T, U, H | 'disjoint'>\n\n /**\n * Available when types T and U are mutually assignable (each type can be assigned to the other).\n *\n * ### Examples\n *\n * ```ts\n * compare<1 | 2, 1 | 2>().mutuallyAssignable // Available since identical union types are mutually assignable\n * ```\n */\n mutuallyAssignable: CompareTypes<T, U, H | 'mutuallyAssignable'>\n },\n | If<Same<T, U>, 'same'>\n | If<Diff<T, U>, 'different'>\n | If<Overlap<T, U>, 'overlap'>\n | If<Disjoint<T, U>, 'disjoint'>\n | If<MutuallyAssignable<T, U>, 'mutuallyAssignable'>\n >,\n H\n>\n\n/**\n * Creates an instance of CompareTypes to perform type-level comparisons between two types.\n * This function enables testing various relationships between types at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T First type to compare\n * @template U Second type to compare\n *\n * @returns A CompareTypes instance with methods to test relationships between T and U\n *\n * ### Examples\n *\n * ```ts\n * // Compare two identical types\n * compare<number, number>().same // Results in an available property\n * // Compare two different but overlapping types\n * compare<4, number>().overlap.different // Results in available properties\n * ```\n */\nexport function compare<T, U>(): CompareTypes<T, U>\nexport function compare<T, U>(t: T, u: U): CompareTypes<T, U>\nexport function compare<T, U>(): CompareTypes<T, U> {\n return NOOP\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lay-sing",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Utilities for compile-time type testing and utility types",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Leawind/lay-sing.git"
|
package/script/main/array.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/array.js
CHANGED
|
File without changes
|
package/script/main/array.js.map
CHANGED
|
File without changes
|
package/script/main/async.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/async.js
CHANGED
|
File without changes
|
package/script/main/async.js.map
CHANGED
|
File without changes
|
package/script/main/boolean.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/boolean.js
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/control.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/control.js
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/doc.d.ts
CHANGED
|
File without changes
|
package/script/main/doc.d.ts.map
CHANGED
|
File without changes
|
package/script/main/doc.js
CHANGED
|
File without changes
|
package/script/main/doc.js.map
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/script/main/function.js
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/index.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/index.js
CHANGED
|
File without changes
|
package/script/main/index.js.map
CHANGED
|
File without changes
|
package/script/main/json.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/json.js
CHANGED
|
File without changes
|
package/script/main/json.js.map
CHANGED
|
File without changes
|
package/script/main/key.d.ts
CHANGED
|
File without changes
|
package/script/main/key.d.ts.map
CHANGED
|
File without changes
|
package/script/main/key.js
CHANGED
|
File without changes
|
package/script/main/key.js.map
CHANGED
|
File without changes
|
package/script/main/object.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/script/main/object.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/script/main/type/set.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/script/package.json
CHANGED
|
File without changes
|
package/script/test-utils.d.ts
CHANGED
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,EAAE,EACF,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACL,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,EAAE,EACF,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACL,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;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,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,GAC3B,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,GAC5B,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,GAC9B,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,oBAAoB,CAAC,CACrD,EACD,CAAC,CACF,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACnD,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
package/script/test-utils.js
CHANGED
|
@@ -44,6 +44,14 @@ exports.NOOP = new Proxy(function () {
|
|
|
44
44
|
return exports.NOOP;
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
+
set: () => true,
|
|
48
|
+
getOwnPropertyDescriptor: () => ({
|
|
49
|
+
configurable: true,
|
|
50
|
+
value: exports.NOOP,
|
|
51
|
+
}),
|
|
52
|
+
getPrototypeOf: () => null,
|
|
53
|
+
has: () => true,
|
|
54
|
+
ownKeys: () => ['prototype'],
|
|
47
55
|
});
|
|
48
56
|
function expect() {
|
|
49
57
|
return exports.NOOP;
|
package/script/test-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":";;;AA2TA,wBAEC;AA+GD,0BAEC;AAjaD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACU,QAAA,IAAI,GAAQ,IAAI,KAAK,CAChC;IACE,OAAO,YAAI,CAAA;AACb,CAAC,EACD;IACE,GAAG,CAAC,CAAC,EAAE,IAAI;QACT,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACT,OAAO,SAAS,CAAA;YAClB,KAAK,SAAS,CAAC;YACf,KAAK,UAAU,CAAC;YAChB,KAAK,MAAM,CAAC,WAAW;gBACrB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAA;YACvB;gBACE,OAAO,YAAI,CAAA;QACf,CAAC;IACH,CAAC;CACF,CACF,CAAA;AAkQD,SAAgB,MAAM;IACpB,OAAO,YAAI,CAAA;AACb,CAAC;AA+GD,SAAgB,OAAO;IACrB,OAAO,YAAI,CAAA;AACb,CAAC","sourcesContent":["// deno-lint-ignore-file no-explicit-any\nimport type {\n Diff,\n Disjoint,\n Extends,\n If,\n MutuallyAssignable,\n Overlap,\n ProperExtend,\n SafePick,\n Same,\n} from './main/index.js'\n\n/**\n * A universal no-op placeholder implemented via `Proxy`.\n *\n * `NOOP` can be accessed, called, or chained indefinitely without throwing.\n * Every operation returns itself, making it safe to use as a dummy fallback\n * for APIs, optional hooks, or unimplemented interfaces.\n *\n * ### Special behaviors\n *\n * - Callable: invoking `NOOP()` returns `NOOP`\n * - Property access: `NOOP.anything` returns `NOOP`\n * - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise\n * - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields\n * a stable string representation: `\"[NOOP]\"`\n *\n * This is useful in scenarios where a value is required syntactically but\n * should perform no action and never fail at runtime.\n *\n * ### Examples\n *\n * ```ts\n * NOOP.foo.bar().baz.qux; // safe, returns NOOP\n * String(NOOP); // \"[NOOP]\"\n * await NOOP; // does not await (not thenable)\n * ```\n */\nexport const NOOP: any = new Proxy(\n function () {\n return NOOP\n },\n {\n get(_, prop) {\n switch (prop) {\n case 'then':\n return undefined\n case 'valueOf':\n case 'toString':\n case Symbol.toPrimitive:\n return () => '[NOOP]'\n default:\n return NOOP\n }\n },\n },\n)\n\n/**\n * Represents the result of a type assertion based on a boolean condition.\n * If the condition is true, the result has a `success` property; otherwise, it has a `fail` property.\n *\n * @template B The boolean condition result (true or false)\n * @template R The type of the result value (default is void)\n */\ntype Result<B extends true | false, R = void> = B extends true ? {\n /**\n * ## Expect to succeed without type error\n */\n success: R\n }\n : {\n /**\n * ## Expect to fail with type error\n */\n fail: R\n }\n\n/**\n * Type-level testing utility that allows checking various relationships between types.\n * Provides methods to test type equality, extension, properties, and more.\n *\n * @template T The type being tested\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Test if two types are identical\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<2>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * // Test if type has a specific property\n * expect<{name: string}>().toHaveProperty<'name'>().success\n * ```\n */\nexport type ExpectType<T, H extends PropertyKey = never> = Omit<\n (\n & {\n T: T\n inspect: { [K in keyof T]: T[K] }\n\n /**\n * Tests if the current type is exactly the same as the provided type U.\n *\n * @template U The type to compare with\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBe<any>().success\n * expect<never>().toBe<never>().success\n * expect<false>().toBe<true>().fail\n * ```\n */\n toBe<U>(): Result<Same<T, U>>\n\n /**\n * Tests if the current type T extends the provided type U.\n *\n * @template U The type to check extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * expect<'hello'>().toExtend<string>().success\n * ```\n */\n toExtend<U>(): Result<Extends<T, U>>\n\n /**\n * Tests if the current type T properly extends the provided type U (extends but is not the same).\n *\n * @template U The type to check proper extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<2>().toProperExtend<number>().success\n * expect<'a' | 'b'>().toProperExtend<string>().success\n * expect<number>().toProperExtend<number>().fail\n * ```\n */\n toProperExtend<U>(): Result<ProperExtend<T, U>>\n\n /**\n * Tests if the current type T has a property with key K.\n *\n * @template K The property key to check for\n *\n * ### Examples\n *\n * ```ts\n * type WithProp = { prop: string; another: number }\n * expect<WithProp>().toHaveProperty<'prop'>().success\n * expect<WithProp>().toHaveProperty<'another'>().success\n * expect<WithProp>().toHaveProperty<'missing'>().fail\n * ```\n */\n toHaveProperty<K extends PropertyKey>(): Result<Extends<K, keyof T>>\n }\n & SafePick<\n {\n /**\n * Tests if the current type extends the Number primitive type.\n * Available only if the current type extends number.\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtendNumber // Available and would succeed\n * ```\n */\n toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>\n\n /**\n * Tests if the current type extends the String primitive type.\n * Available only if the current type extends string.\n *\n * ### Examples\n *\n * ```ts\n * expect<'hello'>().toExtendString // Available and would succeed\n * ```\n */\n toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>\n\n /**\n * Tests if the current type extends the Boolean primitive type.\n * Available only if the current type extends boolean.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toExtendBoolean // Available and would succeed\n * ```\n */\n toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>\n },\n | If<Extends<T, number>, 'toExtendNumber'>\n | If<Extends<T, string>, 'toExtendString'>\n | If<Extends<T, boolean>, 'toExtendBoolean'>\n >\n & SafePick<\n {\n /**\n * Tests if the current type is exactly `any`.\n * Available only if the current type is `any`.\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBeAny // Available and would succeed\n * ```\n */\n toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `never`.\n * Available only if the current type is `never`.\n *\n * ### Examples\n *\n * ```ts\n * expect<never>().toBeNever // Available and would succeed\n * ```\n */\n toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `unknown`.\n * Available only if the current type is `unknown`.\n *\n * ### Examples\n *\n * ```ts\n * expect<unknown>().toBeUnknown // Available and would succeed\n * ```\n */\n toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `void`.\n * Available only if the current type is `void`.\n *\n * ### Examples\n *\n * ```ts\n * expect<void>().toBeVoid // Available and would succeed\n * ```\n */\n toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `true` (boolean literal).\n * Available only if the current type is `true`.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toBeTrue // Available and would succeed\n * ```\n */\n toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>\n\n /**\n * Tests if the current type is exactly `false` (boolean literal).\n * Available only if the current type is `false`.\n *\n * ### Examples\n *\n * ```ts\n * expect<false>().toBeFalse // Available and would succeed\n * ```\n */\n toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>\n },\n | If<Same<T, any>, 'toBeAny'>\n | If<Same<T, never>, 'toBeNever'>\n | If<Same<T, unknown>, 'toBeUnknown'>\n | If<Same<T, void>, 'toBeVoid'>\n | If<Same<T, true>, 'toBeTrue'>\n | If<Same<T, false>, 'toBeFalse'>\n >\n ),\n H\n>\n\n/**\n * Creates an instance of ExpectType to perform type-level assertions on the given type.\n * This function enables testing various type relationships at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T The type to be tested\n *\n * @returns An ExpectType instance with methods to test type relationships\n *\n * ### Examples\n *\n * ```ts\n * // Test exact type equality\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * ```\n */\nexport function expect<T>(): ExpectType<T>\nexport function expect<T>(_: T): ExpectType<T>\nexport function expect<T>(): ExpectType<T> {\n return NOOP\n}\n\n/**\n * Type-level utility that compares two types and provides methods to test their relationship.\n * Offers options to check if types are same, different, overlapping, disjoint, or mutually assignable.\n *\n * @template T First type to compare\n * @template U Second type to compare\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Check if two types are the same\n * compare<number, number>().same // Available\n * // Check if two types are different\n * compare<number, string>().different // Available\n * // Check if two types overlap\n * compare<4, number>().overlap.different // Available\n * ```\n */\nexport type CompareTypes<T, U, H extends PropertyKey = never> = Omit<\n SafePick<\n {\n /**\n * Available when types T and U are exactly the same.\n *\n * ### Examples\n *\n * ```ts\n * compare<3, 3>().same // Available\n * compare<boolean, boolean>().same // Available\n * ```\n */\n same: CompareTypes<T, U, H | 'same'>\n\n /**\n * Available when types T and U are different.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different // Available\n * compare<number, 4>().different // Available\n * ```\n */\n different: CompareTypes<T, U, H | 'different'>\n\n /**\n * Available when types T and U have some overlap.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, number>().overlap // Available since 4 overlaps with number\n * ```\n */\n overlap: CompareTypes<T, U, H | 'overlap'>\n\n /**\n * Available when types T and U have no overlap (are disjoint).\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different.disjoint // Available since 4 and 'abc' are disjoint\n * ```\n */\n disjoint: CompareTypes<T, U, H | 'disjoint'>\n\n /**\n * Available when types T and U are mutually assignable (each type can be assigned to the other).\n *\n * ### Examples\n *\n * ```ts\n * compare<1 | 2, 1 | 2>().mutuallyAssignable // Available since identical union types are mutually assignable\n * ```\n */\n mutuallyAssignable: CompareTypes<T, U, H | 'mutuallyAssignable'>\n },\n | If<Same<T, U>, 'same'>\n | If<Diff<T, U>, 'different'>\n | If<Overlap<T, U>, 'overlap'>\n | If<Disjoint<T, U>, 'disjoint'>\n | If<MutuallyAssignable<T, U>, 'mutuallyAssignable'>\n >,\n H\n>\n\n/**\n * Creates an instance of CompareTypes to perform type-level comparisons between two types.\n * This function enables testing various relationships between types at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T First type to compare\n * @template U Second type to compare\n *\n * @returns A CompareTypes instance with methods to test relationships between T and U\n *\n * ### Examples\n *\n * ```ts\n * // Compare two identical types\n * compare<number, number>().same // Results in an available property\n * // Compare two different but overlapping types\n * compare<4, number>().overlap.different // Results in available properties\n * ```\n */\nexport function compare<T, U>(): CompareTypes<T, U>\nexport function compare<T, U>(t: T, u: U): CompareTypes<T, U>\nexport function compare<T, U>(): CompareTypes<T, U> {\n return NOOP\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":";;;AAmUA,wBAEC;AA+GD,0BAEC;AAzaD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACU,QAAA,IAAI,GAAQ,IAAI,KAAK,CAChC;IACE,OAAO,YAAI,CAAA;AACb,CAAC,EACD;IACE,GAAG,CAAC,CAAC,EAAE,IAAI;QACT,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM;gBACT,OAAO,SAAS,CAAA;YAClB,KAAK,SAAS,CAAC;YACf,KAAK,UAAU,CAAC;YAChB,KAAK,MAAM,CAAC,WAAW;gBACrB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAA;YACvB;gBACE,OAAO,YAAI,CAAA;QACf,CAAC;IACH,CAAC;IACD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;IACf,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/B,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,YAAI;KACZ,CAAC;IACF,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;IAC1B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;IACf,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC;CAC7B,CACF,CAAA;AAkQD,SAAgB,MAAM;IACpB,OAAO,YAAI,CAAA;AACb,CAAC;AA+GD,SAAgB,OAAO;IACrB,OAAO,YAAI,CAAA;AACb,CAAC","sourcesContent":["// deno-lint-ignore-file no-explicit-any\nimport type {\n Diff,\n Disjoint,\n Extends,\n If,\n MutuallyAssignable,\n Overlap,\n ProperExtend,\n SafePick,\n Same,\n} from './main/index.js'\n\n/**\n * A universal no-op placeholder implemented via `Proxy`.\n *\n * `NOOP` can be accessed, called, or chained indefinitely without throwing.\n * Every operation returns itself, making it safe to use as a dummy fallback\n * for APIs, optional hooks, or unimplemented interfaces.\n *\n * ### Special behaviors\n *\n * - Callable: invoking `NOOP()` returns `NOOP`\n * - Property access: `NOOP.anything` returns `NOOP`\n * - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise\n * - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields\n * a stable string representation: `\"[NOOP]\"`\n *\n * This is useful in scenarios where a value is required syntactically but\n * should perform no action and never fail at runtime.\n *\n * ### Examples\n *\n * ```ts\n * NOOP.foo.bar().baz.qux; // safe, returns NOOP\n * String(NOOP); // \"[NOOP]\"\n * await NOOP; // does not await (not thenable)\n * ```\n */\nexport const NOOP: any = new Proxy(\n function () {\n return NOOP\n },\n {\n get(_, prop) {\n switch (prop) {\n case 'then':\n return undefined\n case 'valueOf':\n case 'toString':\n case Symbol.toPrimitive:\n return () => '[NOOP]'\n default:\n return NOOP\n }\n },\n set: () => true,\n getOwnPropertyDescriptor: () => ({\n configurable: true,\n value: NOOP,\n }),\n getPrototypeOf: () => null,\n has: () => true,\n ownKeys: () => ['prototype'],\n },\n)\n\n/**\n * Represents the result of a type assertion based on a boolean condition.\n * If the condition is true, the result has a `success` property; otherwise, it has a `fail` property.\n *\n * @template B The boolean condition result (true or false)\n * @template R The type of the result value (default is void)\n */\ntype Result<B extends true | false, R = void> = B extends true ? {\n /**\n * ## Expect to succeed without type error\n */\n success: R\n }\n : {\n /**\n * ## Expect to fail with type error\n */\n fail: R\n }\n\n/**\n * Type-level testing utility that allows checking various relationships between types.\n * Provides methods to test type equality, extension, properties, and more.\n *\n * @template T The type being tested\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Test if two types are identical\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<2>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * // Test if type has a specific property\n * expect<{name: string}>().toHaveProperty<'name'>().success\n * ```\n */\nexport type ExpectType<T, H extends PropertyKey = never> = Omit<\n (\n & {\n T: T\n inspect: { [K in keyof T]: T[K] }\n\n /**\n * Tests if the current type is exactly the same as the provided type U.\n *\n * @template U The type to compare with\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBe<any>().success\n * expect<never>().toBe<never>().success\n * expect<false>().toBe<true>().fail\n * ```\n */\n toBe<U>(): Result<Same<T, U>>\n\n /**\n * Tests if the current type T extends the provided type U.\n *\n * @template U The type to check extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * expect<'hello'>().toExtend<string>().success\n * ```\n */\n toExtend<U>(): Result<Extends<T, U>>\n\n /**\n * Tests if the current type T properly extends the provided type U (extends but is not the same).\n *\n * @template U The type to check proper extension against\n *\n * ### Examples\n *\n * ```ts\n * expect<2>().toProperExtend<number>().success\n * expect<'a' | 'b'>().toProperExtend<string>().success\n * expect<number>().toProperExtend<number>().fail\n * ```\n */\n toProperExtend<U>(): Result<ProperExtend<T, U>>\n\n /**\n * Tests if the current type T has a property with key K.\n *\n * @template K The property key to check for\n *\n * ### Examples\n *\n * ```ts\n * type WithProp = { prop: string; another: number }\n * expect<WithProp>().toHaveProperty<'prop'>().success\n * expect<WithProp>().toHaveProperty<'another'>().success\n * expect<WithProp>().toHaveProperty<'missing'>().fail\n * ```\n */\n toHaveProperty<K extends PropertyKey>(): Result<Extends<K, keyof T>>\n }\n & SafePick<\n {\n /**\n * Tests if the current type extends the Number primitive type.\n * Available only if the current type extends number.\n *\n * ### Examples\n *\n * ```ts\n * expect<3.14>().toExtendNumber // Available and would succeed\n * ```\n */\n toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>\n\n /**\n * Tests if the current type extends the String primitive type.\n * Available only if the current type extends string.\n *\n * ### Examples\n *\n * ```ts\n * expect<'hello'>().toExtendString // Available and would succeed\n * ```\n */\n toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>\n\n /**\n * Tests if the current type extends the Boolean primitive type.\n * Available only if the current type extends boolean.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toExtendBoolean // Available and would succeed\n * ```\n */\n toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>\n },\n | If<Extends<T, number>, 'toExtendNumber'>\n | If<Extends<T, string>, 'toExtendString'>\n | If<Extends<T, boolean>, 'toExtendBoolean'>\n >\n & SafePick<\n {\n /**\n * Tests if the current type is exactly `any`.\n * Available only if the current type is `any`.\n *\n * ### Examples\n *\n * ```ts\n * expect<any>().toBeAny // Available and would succeed\n * ```\n */\n toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `never`.\n * Available only if the current type is `never`.\n *\n * ### Examples\n *\n * ```ts\n * expect<never>().toBeNever // Available and would succeed\n * ```\n */\n toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `unknown`.\n * Available only if the current type is `unknown`.\n *\n * ### Examples\n *\n * ```ts\n * expect<unknown>().toBeUnknown // Available and would succeed\n * ```\n */\n toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `void`.\n * Available only if the current type is `void`.\n *\n * ### Examples\n *\n * ```ts\n * expect<void>().toBeVoid // Available and would succeed\n * ```\n */\n toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>\n\n /**\n * Tests if the current type is exactly `true` (boolean literal).\n * Available only if the current type is `true`.\n *\n * ### Examples\n *\n * ```ts\n * expect<true>().toBeTrue // Available and would succeed\n * ```\n */\n toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>\n\n /**\n * Tests if the current type is exactly `false` (boolean literal).\n * Available only if the current type is `false`.\n *\n * ### Examples\n *\n * ```ts\n * expect<false>().toBeFalse // Available and would succeed\n * ```\n */\n toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>\n },\n | If<Same<T, any>, 'toBeAny'>\n | If<Same<T, never>, 'toBeNever'>\n | If<Same<T, unknown>, 'toBeUnknown'>\n | If<Same<T, void>, 'toBeVoid'>\n | If<Same<T, true>, 'toBeTrue'>\n | If<Same<T, false>, 'toBeFalse'>\n >\n ),\n H\n>\n\n/**\n * Creates an instance of ExpectType to perform type-level assertions on the given type.\n * This function enables testing various type relationships at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T The type to be tested\n *\n * @returns An ExpectType instance with methods to test type relationships\n *\n * ### Examples\n *\n * ```ts\n * // Test exact type equality\n * expect<number>().toBe<number>().success\n * expect<number>().toBe<string>().fail\n * // Test if one type extends another\n * expect<3.14>().toExtend<number>().success\n * expect<2>().toExtend<string>().fail\n * ```\n */\nexport function expect<T>(): ExpectType<T>\nexport function expect<T>(_: T): ExpectType<T>\nexport function expect<T>(): ExpectType<T> {\n return NOOP\n}\n\n/**\n * Type-level utility that compares two types and provides methods to test their relationship.\n * Offers options to check if types are same, different, overlapping, disjoint, or mutually assignable.\n *\n * @template T First type to compare\n * @template U Second type to compare\n * @template H Hidden property keys that are already used (internal tracking)\n *\n * ### Examples\n *\n * ```ts\n * // Check if two types are the same\n * compare<number, number>().same // Available\n * // Check if two types are different\n * compare<number, string>().different // Available\n * // Check if two types overlap\n * compare<4, number>().overlap.different // Available\n * ```\n */\nexport type CompareTypes<T, U, H extends PropertyKey = never> = Omit<\n SafePick<\n {\n /**\n * Available when types T and U are exactly the same.\n *\n * ### Examples\n *\n * ```ts\n * compare<3, 3>().same // Available\n * compare<boolean, boolean>().same // Available\n * ```\n */\n same: CompareTypes<T, U, H | 'same'>\n\n /**\n * Available when types T and U are different.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different // Available\n * compare<number, 4>().different // Available\n * ```\n */\n different: CompareTypes<T, U, H | 'different'>\n\n /**\n * Available when types T and U have some overlap.\n *\n * ### Examples\n *\n * ```ts\n * compare<4, number>().overlap // Available since 4 overlaps with number\n * ```\n */\n overlap: CompareTypes<T, U, H | 'overlap'>\n\n /**\n * Available when types T and U have no overlap (are disjoint).\n *\n * ### Examples\n *\n * ```ts\n * compare<4, 'abc'>().different.disjoint // Available since 4 and 'abc' are disjoint\n * ```\n */\n disjoint: CompareTypes<T, U, H | 'disjoint'>\n\n /**\n * Available when types T and U are mutually assignable (each type can be assigned to the other).\n *\n * ### Examples\n *\n * ```ts\n * compare<1 | 2, 1 | 2>().mutuallyAssignable // Available since identical union types are mutually assignable\n * ```\n */\n mutuallyAssignable: CompareTypes<T, U, H | 'mutuallyAssignable'>\n },\n | If<Same<T, U>, 'same'>\n | If<Diff<T, U>, 'different'>\n | If<Overlap<T, U>, 'overlap'>\n | If<Disjoint<T, U>, 'disjoint'>\n | If<MutuallyAssignable<T, U>, 'mutuallyAssignable'>\n >,\n H\n>\n\n/**\n * Creates an instance of CompareTypes to perform type-level comparisons between two types.\n * This function enables testing various relationships between types at compile time.\n * NOTE: This function does nothing at runtime and is purely for type-level testing.\n *\n * @template T First type to compare\n * @template U Second type to compare\n *\n * @returns A CompareTypes instance with methods to test relationships between T and U\n *\n * ### Examples\n *\n * ```ts\n * // Compare two identical types\n * compare<number, number>().same // Results in an available property\n * // Compare two different but overlapping types\n * compare<4, number>().overlap.different // Results in available properties\n * ```\n */\nexport function compare<T, U>(): CompareTypes<T, U>\nexport function compare<T, U>(t: T, u: U): CompareTypes<T, U>\nexport function compare<T, U>(): CompareTypes<T, U> {\n return NOOP\n}\n"]}
|