@r_masseater/oxlint-plugin-decision 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -3
- package/dist/{app-Bso1uwY5.mjs → app-D2bguKZ_.mjs} +182 -88
- package/dist/app-D2bguKZ_.mjs.map +1 -0
- package/dist/claim-rule-B0LCcxxc.mjs +36 -0
- package/dist/claim-rule-B0LCcxxc.mjs.map +1 -0
- package/dist/cloudflare-worker.mjs +111 -3
- package/dist/cloudflare-worker.mjs.map +1 -1
- package/dist/{index-BOrpK3Iv.d.mts → index-B4wX62VC.d.mts} +2 -2
- package/dist/{index-Cgg-w0hb.d.mts → index-CK88FBE5.d.mts} +691 -349
- package/dist/index.d.mts +2 -3
- package/dist/index.mjs +1 -1
- package/dist/{define-presets-clyqLZxo.mjs → preset-plugin-MKdvpXxa.mjs} +11 -214
- package/dist/preset-plugin-MKdvpXxa.mjs.map +1 -0
- package/dist/presets/ai-slop.d.mts +2 -3
- package/dist/presets/ai-slop.mjs +179 -2
- package/dist/presets/ai-slop.mjs.map +1 -1
- package/dist/presets/index.d.mts +1 -1
- package/dist/presets/index.mjs +1 -1
- package/dist/presets/recommended.d.mts +1 -2
- package/dist/presets/recommended.mjs +1 -2
- package/dist/presets/recommended.mjs.map +1 -1
- package/dist/presets/review-only.d.mts +1 -2
- package/dist/presets/review-only.mjs +1 -2
- package/dist/presets/review-only.mjs.map +1 -1
- package/dist/presets/strict.d.mts +1 -2
- package/dist/presets/strict.mjs +1 -2
- package/dist/presets/strict.mjs.map +1 -1
- package/dist/serve-decisions-D6M-l2uy.mjs +232 -0
- package/dist/serve-decisions-D6M-l2uy.mjs.map +1 -0
- package/dist/typesafe-worker.mjs +29 -0
- package/dist/typesafe-worker.mjs.map +1 -0
- package/dist/{decision-BtTZ52be.mjs → wire-CKpt_MBX.mjs} +56 -261
- package/dist/wire-CKpt_MBX.mjs.map +1 -0
- package/package.json +26 -29
- package/skills/write-decision-rules/SKILL.md +6 -7
- package/skills/write-decision-rules/references/tuning.md +3 -5
- package/dist/app-Bso1uwY5.mjs.map +0 -1
- package/dist/decision-BtTZ52be.mjs.map +0 -1
- package/dist/define-presets-clyqLZxo.mjs.map +0 -1
- package/dist/index-D7VrRpTx.d.mts +0 -6
- package/dist/openrouter-app.d.mts +0 -19
- package/dist/openrouter-app.mjs +0 -1
- package/dist/openrouter-worker.mjs +0 -15
- package/dist/openrouter-worker.mjs.map +0 -1
- package/dist/preset-plugin-AAwedMeS.mjs +0 -10
- package/dist/preset-plugin-AAwedMeS.mjs.map +0 -1
- package/dist/serve-decisions-CjlhvYm7.mjs +0 -290
- package/dist/serve-decisions-CjlhvYm7.mjs.map +0 -1
- package/skills/write-decision-rules/references/providers.md +0 -55
- /package/dist/{openrouter-worker.d.mts → typesafe-worker.d.mts} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Array as Array$1, Effect, Option, Result, Schema } from "effect";
|
|
2
|
-
import { Answer, ChoiceQuestion, DecisionsRequest, DecisionsResponse, NoulQuestion } from "@effect/ai-openrouter/OpenRouterSchema";
|
|
3
2
|
//#endregion
|
|
4
3
|
//#region src-js/plugins/globals.d.ts
|
|
5
4
|
/**
|
|
@@ -34,11 +33,67 @@ type JsonObject = {
|
|
|
34
33
|
*/
|
|
35
34
|
type Options = JsonValue[];
|
|
36
35
|
//#endregion
|
|
37
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
36
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/primitive.d.ts
|
|
37
|
+
/**
|
|
38
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
39
|
+
|
|
40
|
+
@category Type
|
|
41
|
+
*/
|
|
42
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/keys-of-union.d.ts
|
|
45
|
+
/**
|
|
46
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
47
|
+
|
|
48
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
49
|
+
|
|
50
|
+
@see https://stackoverflow.com/a/49402091
|
|
51
|
+
|
|
52
|
+
@example
|
|
53
|
+
```
|
|
54
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
55
|
+
|
|
56
|
+
type A = {
|
|
57
|
+
common: string;
|
|
58
|
+
a: number;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type B = {
|
|
62
|
+
common: string;
|
|
63
|
+
b: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type C = {
|
|
67
|
+
common: string;
|
|
68
|
+
c: boolean;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type Union = A | B | C;
|
|
72
|
+
|
|
73
|
+
type CommonKeys = keyof Union;
|
|
74
|
+
//=> 'common'
|
|
75
|
+
|
|
76
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
77
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
@category Object
|
|
81
|
+
*/
|
|
82
|
+
type KeysOfUnion<ObjectType> =
|
|
83
|
+
// Adds no keys, since these are the keys all members share, but it lets the compiler accept a key narrowed with `keyof` when `ObjectType` is generic, such as a conditional type that is not resolved yet.
|
|
84
|
+
keyof ObjectType |
|
|
85
|
+
// Infer a union of each member's keys from function return types.
|
|
86
|
+
// This avoids the record intersections and extra `& Union` that `UnionToIntersection` would create.
|
|
87
|
+
// The outer conditional prevents unresolved generic union keys from being treated as safe to index every member.
|
|
88
|
+
((ObjectType extends unknown ? () => keyof ObjectType : never) extends (() => infer Keys extends PropertyKey) ? Keys : never);
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/is-any.d.ts
|
|
38
91
|
/**
|
|
39
92
|
Returns a boolean for whether the given type is `any`.
|
|
40
93
|
|
|
41
|
-
|
|
94
|
+
Returns `false` for `never` and `unknown`. Unions are normalized before the check.
|
|
95
|
+
|
|
96
|
+
@see https://stackoverflow.com/a/49928360/1490091
|
|
42
97
|
|
|
43
98
|
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
44
99
|
|
|
@@ -65,178 +120,344 @@ const anyA = get(anyObject, 'a');
|
|
|
65
120
|
*/
|
|
66
121
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
67
122
|
//#endregion
|
|
68
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
123
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/is-never.d.ts
|
|
69
124
|
/**
|
|
70
|
-
Returns a boolean for whether the given
|
|
125
|
+
Returns a boolean for whether the given type is `never`.
|
|
71
126
|
|
|
72
|
-
|
|
127
|
+
@see https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
128
|
+
@see https://stackoverflow.com/a/53984913/10292952
|
|
129
|
+
@see https://www.zhenghao.io/posts/ts-never
|
|
130
|
+
|
|
131
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
73
132
|
|
|
74
133
|
@example
|
|
75
134
|
```
|
|
76
|
-
import type {
|
|
77
|
-
|
|
78
|
-
type User = {
|
|
79
|
-
name: string;
|
|
80
|
-
surname: string;
|
|
135
|
+
import type {IsNever, And} from 'type-fest';
|
|
81
136
|
|
|
82
|
-
|
|
83
|
-
|
|
137
|
+
type A = IsNever<never>;
|
|
138
|
+
//=> true
|
|
84
139
|
|
|
85
|
-
type
|
|
86
|
-
|
|
87
|
-
surname?: string;
|
|
88
|
-
};
|
|
140
|
+
type B = IsNever<any>;
|
|
141
|
+
//=> false
|
|
89
142
|
|
|
90
|
-
type
|
|
91
|
-
//=>
|
|
143
|
+
type C = IsNever<unknown>;
|
|
144
|
+
//=> false
|
|
92
145
|
|
|
93
|
-
type
|
|
146
|
+
type D = IsNever<never[]>;
|
|
94
147
|
//=> false
|
|
95
148
|
|
|
96
|
-
type
|
|
97
|
-
//=>
|
|
149
|
+
type E = IsNever<object>;
|
|
150
|
+
//=> false
|
|
98
151
|
|
|
99
|
-
type
|
|
152
|
+
type F = IsNever<string>;
|
|
100
153
|
//=> false
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
@example
|
|
157
|
+
```
|
|
158
|
+
import type {IsNever} from 'type-fest';
|
|
159
|
+
|
|
160
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
161
|
+
|
|
162
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
163
|
+
type A = IsTrue<never>;
|
|
164
|
+
//=> never
|
|
165
|
+
|
|
166
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
167
|
+
type IsTrueFixed<T> =
|
|
168
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
101
169
|
|
|
102
|
-
type
|
|
103
|
-
//=>
|
|
170
|
+
type B = IsTrueFixed<never>;
|
|
171
|
+
//=> false
|
|
104
172
|
```
|
|
105
173
|
|
|
106
174
|
@category Type Guard
|
|
107
175
|
@category Utilities
|
|
108
176
|
*/
|
|
109
|
-
type
|
|
177
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
110
178
|
//#endregion
|
|
111
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
179
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/unknown-array.d.ts
|
|
112
180
|
/**
|
|
113
|
-
|
|
181
|
+
Represents an array with `unknown` value.
|
|
114
182
|
|
|
115
|
-
|
|
183
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
116
184
|
|
|
117
185
|
@example
|
|
118
186
|
```
|
|
119
|
-
import type {
|
|
187
|
+
import type {UnknownArray} from 'type-fest';
|
|
120
188
|
|
|
121
|
-
type
|
|
122
|
-
name: string;
|
|
123
|
-
surname: string;
|
|
124
|
-
|
|
125
|
-
luckyNumber?: number;
|
|
126
|
-
};
|
|
189
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
127
190
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
131
|
-
};
|
|
191
|
+
type A = IsArray<['foo']>;
|
|
192
|
+
//=> true
|
|
132
193
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
194
|
+
type B = IsArray<readonly number[]>;
|
|
195
|
+
//=> true
|
|
136
196
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
luckyNumber: REMOVE_FIELD,
|
|
140
|
-
};
|
|
197
|
+
type C = IsArray<string>;
|
|
198
|
+
//=> false
|
|
141
199
|
```
|
|
142
200
|
|
|
143
|
-
@category
|
|
201
|
+
@category Type
|
|
202
|
+
@category Array
|
|
144
203
|
*/
|
|
145
|
-
type
|
|
146
|
-
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never; }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
147
|
-
: never; // Should never happen
|
|
204
|
+
type UnknownArray = readonly unknown[];
|
|
148
205
|
//#endregion
|
|
149
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
206
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/collapse-literals.d.ts
|
|
150
207
|
/**
|
|
151
|
-
|
|
208
|
+
Collapse literal union members into broader types already present in the union.
|
|
152
209
|
|
|
153
|
-
|
|
210
|
+
Use-case: Normalize a {@link LiteralUnion} for type comparisons or conditional types while preserving unrelated union members. Complements {@link ExtractLiterals}, which keeps only the literals.
|
|
211
|
+
|
|
212
|
+
Unlike {@link LiteralToPrimitive}, this does not widen every literal: a literal changes only when a broader member of the union already covers it. Members that are not primitives are returned unchanged. It only removes the intersection with the empty object type (`& {}`) from primitive members, which lets TypeScript merge the union. This includes the `& Record<never, never>` of {@link LiteralUnion}, because `Record<never, never>` is `{}`. This is not recursive, and it does not merge the members of a branded or tagged type, because each member keeps its own brand or tag.
|
|
154
213
|
|
|
155
214
|
@example
|
|
156
215
|
```
|
|
157
|
-
import type {
|
|
216
|
+
import type {CollapseLiterals, LiteralUnion} from 'type-fest';
|
|
158
217
|
|
|
159
|
-
|
|
160
|
-
Entity extends object,
|
|
161
|
-
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
162
|
-
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
218
|
+
type Theme = LiteralUnion<'auto' | 'dark', string>;
|
|
163
219
|
|
|
164
|
-
type
|
|
165
|
-
|
|
166
|
-
surname: string;
|
|
167
|
-
luckyNumber?: number;
|
|
168
|
-
};
|
|
220
|
+
type ThemeValue = CollapseLiterals<Theme>;
|
|
221
|
+
//=> string
|
|
169
222
|
|
|
170
|
-
|
|
171
|
-
|
|
223
|
+
type OptionalTheme = CollapseLiterals<Theme | null | undefined>;
|
|
224
|
+
//=> string | null | undefined
|
|
172
225
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
226
|
+
type EventName = CollapseLiterals<LiteralUnion<'click' | 'onChange', `on${string}`>>;
|
|
227
|
+
//=> 'click' | `on${string}`
|
|
228
|
+
|
|
229
|
+
type Size = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;
|
|
230
|
+
//=> number
|
|
231
|
+
|
|
232
|
+
type KnownTheme = CollapseLiterals<'auto' | 'dark'>;
|
|
233
|
+
//=> 'auto' | 'dark'
|
|
176
234
|
```
|
|
177
235
|
|
|
178
|
-
@
|
|
236
|
+
@see {@link LiteralUnion}
|
|
237
|
+
@see {@link ExtractLiterals}
|
|
238
|
+
@see {@link LiteralToPrimitive}
|
|
239
|
+
@category Type
|
|
179
240
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
241
|
+
// Distribute first, so an object member in the union cannot stop the other members from collapsing.
|
|
242
|
+
// The primitive check also keeps `{}`-like inputs away from the `infer`, which turns them into `unknown`.
|
|
243
|
+
type CollapseLiterals<Union> = Union extends Primitive ? Union extends (infer Collapsed) & {} ? Collapsed : Union : Union;
|
|
182
244
|
//#endregion
|
|
183
|
-
//#region ../../node_modules/.pnpm/
|
|
245
|
+
//#region ../../node_modules/.pnpm/tagged-tag@1.0.0/node_modules/tagged-tag/index.d.ts
|
|
246
|
+
declare const tag: unique symbol;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/union-member.d.ts
|
|
184
249
|
/**
|
|
185
|
-
Returns
|
|
250
|
+
Returns an arbitrary member of a union type.
|
|
186
251
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
252
|
+
Use-cases:
|
|
253
|
+
- Implementing recursive type functions that accept a union type.
|
|
190
254
|
|
|
191
|
-
|
|
255
|
+
@example
|
|
256
|
+
```
|
|
257
|
+
import type {UnionMember, IsNever} from 'type-fest';
|
|
258
|
+
|
|
259
|
+
type UnionLength<T, Acc extends any[] = []> =
|
|
260
|
+
UnionMember<T> extends infer Member
|
|
261
|
+
? IsNever<Member> extends false
|
|
262
|
+
? UnionLength<Exclude<T, Member>, [...Acc, Member]>
|
|
263
|
+
: Acc['length']
|
|
264
|
+
: never;
|
|
265
|
+
|
|
266
|
+
type T1 = UnionLength<'foo' | 'bar' | 'baz'>;
|
|
267
|
+
//=> 3
|
|
268
|
+
|
|
269
|
+
type T2 = UnionLength<{a: string}>;
|
|
270
|
+
//=> 1
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- Picking an arbitrary member from a union
|
|
192
274
|
|
|
193
275
|
@example
|
|
194
276
|
```
|
|
195
|
-
import type {
|
|
277
|
+
import type {UnionMember, Primitive, LiteralToPrimitive} from 'type-fest';
|
|
196
278
|
|
|
197
|
-
type
|
|
279
|
+
type IsHomogenous<T extends Primitive> = [T] extends [LiteralToPrimitive<UnionMember<T>>] ? true : false;
|
|
280
|
+
|
|
281
|
+
type T1 = IsHomogenous<1 | 2 | 3 | 4>;
|
|
198
282
|
//=> true
|
|
199
283
|
|
|
200
|
-
type
|
|
201
|
-
//=>
|
|
284
|
+
type T2 = IsHomogenous<'foo' | 'bar'>;
|
|
285
|
+
//=> true
|
|
202
286
|
|
|
203
|
-
type
|
|
287
|
+
type T3 = IsHomogenous<'foo' | 'bar' | 1>;
|
|
204
288
|
//=> false
|
|
289
|
+
```
|
|
205
290
|
|
|
206
|
-
|
|
207
|
-
//=> false
|
|
291
|
+
Returns `never` when the input is `never`.
|
|
208
292
|
|
|
209
|
-
|
|
210
|
-
|
|
293
|
+
@example
|
|
294
|
+
```
|
|
295
|
+
import type {UnionMember} from 'type-fest';
|
|
211
296
|
|
|
212
|
-
type
|
|
213
|
-
//=>
|
|
297
|
+
type LastNever = UnionMember<never>;
|
|
298
|
+
//=> never
|
|
214
299
|
```
|
|
215
300
|
|
|
301
|
+
@category Type
|
|
302
|
+
*/
|
|
303
|
+
type UnionMember<T> = IsNever<T> extends true ? never :
|
|
304
|
+
// This infers the intersection itself instead of using `UnionToIntersection`, whose `& Union` makes TypeScript distribute the intersection over every member, which is slow for large unions and for types like `Tagged` that call this in a loop.
|
|
305
|
+
(T extends any ? (member: () => T) => void : never) extends ((member: infer Intersection) => void) ? Intersection extends (() => (infer R)) ? R : never : never;
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/tagged.d.ts
|
|
308
|
+
// Declaration emit cannot name the `tag` symbol unless the user's file imports it. So exporting a value whose inferred type contains the `[tag]` key directly (for example, after spreading a tagged object) fails with TS4023: https://github.com/microsoft/TypeScript/issues/64812
|
|
309
|
+
// eslint-disable-next-line type-fest/require-exported-types
|
|
310
|
+
type TagContainer<Token> = {
|
|
311
|
+
readonly [tag]: Token;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
The tag part of a {@link Tagged} type, without the underlying type.
|
|
315
|
+
|
|
316
|
+
`Tagged<Type, TagName, TagMetadata>` is `Type & Tag<TagName, TagMetadata>`. Use `Tagged` to create tagged types. Use `Tag` to accept any type that has a given tag, whatever its underlying type is.
|
|
317
|
+
|
|
318
|
+
TypeScript can also show a tagged type as an intersection with `Tag`, for example in emitted declaration files. This is why `Tag` is exported.
|
|
319
|
+
|
|
216
320
|
@example
|
|
217
321
|
```
|
|
218
|
-
import type {
|
|
322
|
+
import type {Tag, Tagged} from 'type-fest';
|
|
219
323
|
|
|
220
|
-
type
|
|
324
|
+
type Url = Tagged<string, 'URL'>;
|
|
325
|
+
type UrlObject = Tagged<URL, 'URL'>;
|
|
221
326
|
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
//=> never
|
|
327
|
+
// Accepts any type that has the `URL` tag, with any metadata.
|
|
328
|
+
declare function fetchUrl(url: Tag<'URL', unknown>): void;
|
|
225
329
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
330
|
+
fetchUrl('https://example.com' as Url);
|
|
331
|
+
fetchUrl(new URL('https://example.com') as UrlObject);
|
|
229
332
|
|
|
230
|
-
|
|
231
|
-
|
|
333
|
+
// @ts-expect-error
|
|
334
|
+
fetchUrl('https://example.com');
|
|
232
335
|
```
|
|
233
336
|
|
|
234
|
-
@category Type
|
|
235
|
-
@category Utilities
|
|
337
|
+
@category Type
|
|
236
338
|
*/
|
|
237
|
-
type
|
|
339
|
+
// Exported so that declaration emit can name it. TypeScript can reduce a `Tagged` type to `Type & Tag<…>` (for example, `Tagged<T, 'A'> & T`), and package `exports` hide this file, so a user's exported value with that type would otherwise fail with TS4023: https://github.com/sindresorhus/type-fest/pull/1243
|
|
340
|
+
type Tag<TagName extends PropertyKey, TagMetadata> = TagContainer<{ [Key in TagName]: TagMetadata; }>;
|
|
341
|
+
/**
|
|
342
|
+
Get the untagged portion of a tagged type created with `Tagged`.
|
|
343
|
+
|
|
344
|
+
For nested tags, keep each tag’s metadata in one layer and add one distinct tag name per layer. Reusing a name with different metadata, or nesting multiple layers that each add several names, is not supported.
|
|
345
|
+
|
|
346
|
+
Why is this necessary?
|
|
347
|
+
|
|
348
|
+
1. Use a `Tagged` type as object keys
|
|
349
|
+
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
350
|
+
|
|
351
|
+
@example
|
|
352
|
+
```
|
|
353
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
354
|
+
|
|
355
|
+
type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
356
|
+
|
|
357
|
+
const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
|
|
358
|
+
SAVINGS: 99,
|
|
359
|
+
CHECKING: 0.1,
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// Without UnwrapTagged, the following expression would throw a type error.
|
|
363
|
+
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
364
|
+
|
|
365
|
+
// Attempting to pass a non-Tagged type to UnwrapTagged will raise a type error.
|
|
366
|
+
// @ts-expect-error
|
|
367
|
+
type WontWork = UnwrapTagged<string>;
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
@example
|
|
371
|
+
```
|
|
372
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
373
|
+
|
|
374
|
+
// Keep a tag’s metadata in one layer.
|
|
375
|
+
type CheckedUserId = Tagged<string, 'Checked', {parsed: true; validated: true}>;
|
|
376
|
+
|
|
377
|
+
type UserId = UnwrapTagged<CheckedUserId>;
|
|
378
|
+
//=> string
|
|
379
|
+
|
|
380
|
+
// Use a distinct tag name for another stage.
|
|
381
|
+
type StoredUserId = Tagged<CheckedUserId, 'Stored', {table: 'users'}>;
|
|
382
|
+
|
|
383
|
+
type StoredUserIdValue = UnwrapTagged<StoredUserId>;
|
|
384
|
+
//=> string
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
@category Type
|
|
388
|
+
*/
|
|
389
|
+
// The constraint accepts a bare `TagContainer` too, so that the deprecated `Opaque` form, which tags with a token rather than a keyed object, can be unwrapped as well.
|
|
390
|
+
type UnwrapTagged<TaggedType extends TagContainer<any>> = RemoveAllTags<TaggedType>;
|
|
391
|
+
type RemoveAllTags<T> = T extends TagContainer<any> ?
|
|
392
|
+
// Every order of removing the tags ends at the same type, so following only one of them avoids branching recursively over every removal order.
|
|
393
|
+
RemoveAllTags<UnionMember<RemoveTag<T>>> : T;
|
|
394
|
+
/**
|
|
395
|
+
Removes a single tag from `T`, returning every possible result.
|
|
396
|
+
|
|
397
|
+
A tag can be applied one tag-name at a time (each application contributes its own layer to the intersection) or as a union of tag names in a single application (one layer holding a multi-key tag object). Because the intersection is only stripped when a layer matches a target tag object exactly, both shapes are peeled here, and only strictly smaller results are kept so that the recursion always makes progress and terminates.
|
|
398
|
+
*/
|
|
399
|
+
type RemoveTag<T extends TagContainer<unknown>> = { [ThisTag in keyof T[typeof tag]]: T extends (infer Underlying) & Tag<ThisTag, T[typeof tag][ThisTag]> ? [Underlying] extends [T] ? never : Underlying : never; }[keyof T[typeof tag]] | (T extends (infer Underlying) & TagContainer<T[typeof tag]> ? [Underlying] extends [T] ? never : Underlying : never);
|
|
238
400
|
//#endregion
|
|
239
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
401
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/unwrap-branded-primitive.d.ts
|
|
402
|
+
/**
|
|
403
|
+
Remove brand properties from primitive types while preserving literal types.
|
|
404
|
+
|
|
405
|
+
Useful for recovering literal keys from branded types. Unlike {@link LiteralToPrimitive}, this does not widen literals. This distributes over unions. Non-primitive members are returned unchanged, including their brands and nested properties. `any`, `never`, and `unknown` are also returned unchanged.
|
|
406
|
+
|
|
407
|
+
@example
|
|
408
|
+
```
|
|
409
|
+
import type {Tagged, UnwrapBrandedPrimitive} from 'type-fest';
|
|
410
|
+
|
|
411
|
+
type Status = ('draft' | 'published') & {readonly __brand: 'Status'};
|
|
412
|
+
|
|
413
|
+
type StatusName = UnwrapBrandedPrimitive<Status>;
|
|
414
|
+
//=> 'draft' | 'published'
|
|
415
|
+
|
|
416
|
+
type StatusCounts = Record<UnwrapBrandedPrimitive<Status>, number>;
|
|
417
|
+
//=> {draft: number; published: number}
|
|
418
|
+
|
|
419
|
+
type UserId = UnwrapBrandedPrimitive<Tagged<string, 'UserId'>>;
|
|
420
|
+
//=> string
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
@example
|
|
424
|
+
```
|
|
425
|
+
import type {UnwrapBrandedPrimitive} from 'type-fest';
|
|
426
|
+
|
|
427
|
+
type Brand = {readonly __brand: unique symbol};
|
|
428
|
+
|
|
429
|
+
type A = UnwrapBrandedPrimitive<string & Brand>;
|
|
430
|
+
//=> string
|
|
431
|
+
|
|
432
|
+
type B = UnwrapBrandedPrimitive<number & Brand>;
|
|
433
|
+
//=> number
|
|
434
|
+
|
|
435
|
+
type C = UnwrapBrandedPrimitive<PropertyKey & Brand>;
|
|
436
|
+
//=> number | string | symbol
|
|
437
|
+
|
|
438
|
+
type D = UnwrapBrandedPrimitive<(1 | 200n | 'foo' | 'bar') & Brand>;
|
|
439
|
+
//=> 1 | 200n | 'foo' | 'bar'
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Custom brands must use a single object with explicit marker properties, such as `string & {brand: 'Id'}`. Optional markers, including a single {@link Flavor}, are supported. Separate custom intersections, such as `string & BrandA & BrandB`, and marker keys shared with any built-in primitive properties are not supported. Index signatures and call or construct signatures are not supported as custom brands. All extra properties are treated as brands, including methods.
|
|
443
|
+
|
|
444
|
+
Nested {@link Tagged} types follow the limits described in {@link UnwrapTagged}. A single legacy {@link Opaque} layer is supported, except with a `never` token. Use {@link UnwrapTagged} to unwrap tagged objects too.
|
|
445
|
+
|
|
446
|
+
@see {@link UnwrapTagged}
|
|
447
|
+
@see {@link LiteralToPrimitive}
|
|
448
|
+
|
|
449
|
+
@category Type
|
|
450
|
+
*/
|
|
451
|
+
type UnwrapBrandedPrimitive<Value> = IfNotAnyOrNever<Value, {
|
|
452
|
+
ifNot: UnwrapBrandedPrimitiveImplementation<Value, Primitive>;
|
|
453
|
+
}>;
|
|
454
|
+
type UnwrapBrandedPrimitiveImplementation<Value, Base> = Value extends Primitive ?
|
|
455
|
+
// Separate tag layers do not match a single object containing all brand properties.
|
|
456
|
+
// `CollapseLiterals` removes `& {}` first, because TypeScript defers `keyof` on types like `` `on${string}` & {} ``.
|
|
457
|
+
UnwrapPrimitiveProperties<CollapseLiterals<Value extends TagContainer<unknown> ? UnwrapTagged<Value> : Value>, Base> : Value;
|
|
458
|
+
type UnwrapPrimitiveProperties<Value, Base> = Value extends (infer Unbranded) & Pick<Value, Exclude<keyof Value, KeysOfUnion<Base>>> ? Unbranded : Value;
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/if.d.ts
|
|
240
461
|
/**
|
|
241
462
|
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
242
463
|
|
|
@@ -331,150 +552,138 @@ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
|
331
552
|
*/
|
|
332
553
|
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
333
554
|
//#endregion
|
|
334
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
555
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/internal/string.d.ts
|
|
335
556
|
/**
|
|
336
|
-
|
|
557
|
+
Convert a string or number key to its template literal representation.
|
|
337
558
|
|
|
338
|
-
|
|
339
|
-
```
|
|
340
|
-
// When `T` is neither `any` nor `never` (like `string`) => Returns `IfNot` branch
|
|
341
|
-
type A = IfNotAnyOrNever<string, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
342
|
-
//=> 'VALID'
|
|
559
|
+
Note: This type is not the return type of the `.toString()` function.
|
|
343
560
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
561
|
+
Keep this separate from the public `ToString`: internal key and path matching relies on preserving branded template literal patterns and `${any}`.
|
|
562
|
+
*/
|
|
563
|
+
type KeyToString<Key> = Key extends string | number ? `${Key}` : never;
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/matching-key.d.ts
|
|
566
|
+
/**
|
|
567
|
+
Resolve a property key to the matching key type in an object, converting between numeric and string forms when needed.
|
|
347
568
|
|
|
348
|
-
|
|
349
|
-
type C = IfNotAnyOrNever<never, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
350
|
-
//=> 'IS_NEVER'
|
|
351
|
-
```
|
|
569
|
+
Useful when composing generic property access utilities that accept either `0` or `'0'` for the same property. Returns `never` if no key matches.
|
|
352
570
|
|
|
353
|
-
|
|
571
|
+
Keys assignable to `keyof ObjectType` are returned unchanged, including keys covered by index signatures. Otherwise, numeric keys are tried as strings, and numeric strings as numbers only if converting back preserves their spelling. For example, `'01'` does not match `1`.
|
|
354
572
|
|
|
355
|
-
|
|
356
|
-
```ts
|
|
357
|
-
import type {StringRepeat} from 'type-fest';
|
|
573
|
+
Distributes over a union of keys. For a union of objects, only keys in `keyof ObjectType` are considered, so a key must be common to all members. Plain strings do not select string enum keys. Array and tuple indices are not bounds-checked.
|
|
358
574
|
|
|
359
|
-
|
|
575
|
+
@example
|
|
576
|
+
```
|
|
577
|
+
import type {MatchingKey} from 'type-fest';
|
|
360
578
|
|
|
361
|
-
|
|
362
|
-
|
|
579
|
+
type StatusMessages = {
|
|
580
|
+
200: 'OK';
|
|
581
|
+
'404': 'Not found';
|
|
582
|
+
};
|
|
363
583
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
367
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
368
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
584
|
+
type SuccessKey = MatchingKey<StatusMessages, '200'>;
|
|
585
|
+
//=> 200
|
|
369
586
|
|
|
370
|
-
|
|
371
|
-
|
|
587
|
+
type NotFoundKey = MatchingKey<StatusMessages, 404>;
|
|
588
|
+
//=> '404'
|
|
372
589
|
|
|
373
|
-
type
|
|
590
|
+
type PickByKey<ObjectType extends object, Key extends PropertyKey> = Pick<ObjectType, MatchingKey<ObjectType, Key>>;
|
|
374
591
|
|
|
375
|
-
type
|
|
376
|
-
//=> ''
|
|
592
|
+
type Success = PickByKey<StatusMessages, '200'>;
|
|
593
|
+
//=> {200: 'OK'}
|
|
377
594
|
```
|
|
595
|
+
|
|
596
|
+
@see {@link PropertyValue} to get the value of the matching property.
|
|
597
|
+
|
|
598
|
+
@category Object
|
|
378
599
|
*/
|
|
379
|
-
type
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
ifNever?: unknown;
|
|
383
|
-
}> = IsAny<T> extends true ? 'ifAny' extends keyof Cases ? Cases['ifAny'] : any : IsNever<T> extends true ? 'ifNever' extends keyof Cases ? Cases['ifNever'] : never : Cases['ifNot'];
|
|
600
|
+
type MatchingKey<ObjectType extends object, Key extends PropertyKey> = Key extends keyof ObjectType ? Key : KeyToString<Key> extends keyof ObjectType ? KeyToString<Key> : Key extends `${infer NumberKey extends number}` ?
|
|
601
|
+
// A numeric-looking string names a number key only when its spelling survives the conversion.
|
|
602
|
+
`${NumberKey}` extends Key ? NumberKey extends keyof ObjectType ? NumberKey : never : never : never;
|
|
384
603
|
//#endregion
|
|
385
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
604
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/numeric.d.ts
|
|
386
605
|
/**
|
|
387
|
-
|
|
606
|
+
Matches the hidden `Infinity` type.
|
|
388
607
|
|
|
389
|
-
|
|
390
|
-
```
|
|
391
|
-
import type {Simplify} from 'type-fest';
|
|
608
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
392
609
|
|
|
393
|
-
|
|
394
|
-
top: number;
|
|
395
|
-
left: number;
|
|
396
|
-
};
|
|
610
|
+
@see {@link NegativeInfinity}
|
|
397
611
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
612
|
+
@category Numeric
|
|
613
|
+
*/
|
|
614
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
615
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
616
|
+
type PositiveInfinity = 1e999;
|
|
617
|
+
/**
|
|
618
|
+
Matches the hidden `-Infinity` type.
|
|
402
619
|
|
|
403
|
-
|
|
404
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
405
|
-
```
|
|
620
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
406
621
|
|
|
407
|
-
|
|
622
|
+
@see {@link PositiveInfinity}
|
|
408
623
|
|
|
409
|
-
|
|
624
|
+
@category Numeric
|
|
625
|
+
*/
|
|
626
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
627
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
628
|
+
type NegativeInfinity = -1e999;
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/string-to-number.d.ts
|
|
631
|
+
/**
|
|
632
|
+
Converts a numeric string to a number.
|
|
410
633
|
|
|
411
634
|
@example
|
|
412
635
|
```
|
|
413
|
-
import type {
|
|
636
|
+
import type {StringToNumber} from 'type-fest';
|
|
414
637
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
bar?: string;
|
|
418
|
-
baz: number | undefined;
|
|
419
|
-
}
|
|
638
|
+
type PositiveInteger = StringToNumber<'1234'>;
|
|
639
|
+
//=> 1234
|
|
420
640
|
|
|
421
|
-
type
|
|
422
|
-
|
|
423
|
-
bar?: string;
|
|
424
|
-
baz: number | undefined;
|
|
425
|
-
};
|
|
641
|
+
type NegativeInteger = StringToNumber<'-1234'>;
|
|
642
|
+
//=> -1234
|
|
426
643
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
const someInterface: SomeInterface = literal;
|
|
644
|
+
type PositiveFloat = StringToNumber<'1234.56'>;
|
|
645
|
+
//=> 1234.56
|
|
430
646
|
|
|
431
|
-
|
|
647
|
+
type NegativeFloat = StringToNumber<'-1234.56'>;
|
|
648
|
+
//=> -1234.56
|
|
432
649
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
// @ts-expect-error
|
|
436
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
437
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
438
|
-
```
|
|
650
|
+
type PositiveInfinity = StringToNumber<'Infinity'>;
|
|
651
|
+
//=> Infinity
|
|
439
652
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
*/
|
|
444
|
-
type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
|
|
445
|
-
//#endregion
|
|
446
|
-
//#region ../../node_modules/.pnpm/type-fest@5.10.0/node_modules/type-fest/source/is-equal.d.ts
|
|
447
|
-
/**
|
|
448
|
-
Returns a boolean for whether the two given types are equal.
|
|
449
|
-
|
|
450
|
-
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
451
|
-
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
653
|
+
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
654
|
+
//=> -Infinity
|
|
655
|
+
```
|
|
452
656
|
|
|
453
|
-
|
|
454
|
-
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
657
|
+
Note: Some strings, such as `'1.50'`, `'0b10'`, `'12_345'`, or an integer too large to be represented exactly like `'9007199254740993'`, may look like they can be converted to numbers, but they don't actually have corresponding numeric literals. So, in such cases, this type produces `never`. See [type-fest#1446](https://github.com/sindresorhus/type-fest/pull/1446) for more details.
|
|
455
658
|
|
|
456
659
|
@example
|
|
457
660
|
```
|
|
458
|
-
import type {
|
|
661
|
+
import type {StringToNumber} from 'type-fest';
|
|
662
|
+
|
|
663
|
+
type FractionalsEndingInZero = StringToNumber<'1.50'>;
|
|
664
|
+
//=> never
|
|
665
|
+
|
|
666
|
+
type NonDecimalBases = StringToNumber<'0b10' | '0o10' | '0x10'>;
|
|
667
|
+
//=> never
|
|
668
|
+
|
|
669
|
+
type NumericSeparators = StringToNumber<'12_345'>;
|
|
670
|
+
//=> never
|
|
459
671
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
type Includes<Value extends readonly any[], Item> =
|
|
463
|
-
Value extends readonly [Value[0], ...infer rest]
|
|
464
|
-
? IsEqual<Value[0], Item> extends true
|
|
465
|
-
? true
|
|
466
|
-
: Includes<rest, Item>
|
|
467
|
-
: false;
|
|
672
|
+
type TooLarge = StringToNumber<'9007199254740993'>;
|
|
673
|
+
//=> never
|
|
468
674
|
```
|
|
469
675
|
|
|
470
|
-
@
|
|
471
|
-
|
|
676
|
+
@see {@link StringToBoolean} - For parsing a boolean string.
|
|
677
|
+
|
|
678
|
+
@category String
|
|
679
|
+
@category Numeric
|
|
680
|
+
@category Template literal
|
|
472
681
|
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
type
|
|
682
|
+
// The parser already returns `number` for `any` and distributes `never` to `never`.
|
|
683
|
+
type StringToNumber<S extends string> = _StringToNumber<S extends object ? UnwrapBrandedPrimitive<S> : S>;
|
|
684
|
+
type _StringToNumber<S extends string> = S extends `${infer N extends number}` ? number extends N ? `${number}` extends S ? N : never : N : string extends S ? number : S extends 'Infinity' ? PositiveInfinity : S extends '-Infinity' ? NegativeInfinity : never;
|
|
476
685
|
//#endregion
|
|
477
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
686
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
478
687
|
/**
|
|
479
688
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
480
689
|
|
|
@@ -485,34 +694,34 @@ Use-cases:
|
|
|
485
694
|
|
|
486
695
|
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
487
696
|
|
|
488
|
-
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string,
|
|
697
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, never>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', never>`.
|
|
489
698
|
|
|
490
|
-
|
|
699
|
+
The `never` value type prevents inherited `Object.prototype` members, such as `toString`, from satisfying an explicitly defined key.
|
|
491
700
|
|
|
492
701
|
```
|
|
493
|
-
const indexed: Record<string,
|
|
702
|
+
const indexed: Record<string, never> = {}; // Allowed
|
|
494
703
|
|
|
495
704
|
// @ts-expect-error
|
|
496
|
-
const keyed: Record<'foo',
|
|
497
|
-
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar",
|
|
705
|
+
const keyed: Record<'foo' | 'bar', never> = {}; // Error
|
|
706
|
+
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", never>': foo, bar
|
|
498
707
|
```
|
|
499
708
|
|
|
500
709
|
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
501
710
|
|
|
502
711
|
```
|
|
503
|
-
type Indexed = {} extends Record<string,
|
|
504
|
-
? '✅ `{}` is assignable to `Record<string,
|
|
505
|
-
: '❌ `{}` is NOT assignable to `Record<string,
|
|
712
|
+
type Indexed = {} extends Record<string, never>
|
|
713
|
+
? '✅ `{}` is assignable to `Record<string, never>`'
|
|
714
|
+
: '❌ `{}` is NOT assignable to `Record<string, never>`';
|
|
506
715
|
|
|
507
716
|
type IndexedResult = Indexed;
|
|
508
|
-
//=> '✅ `{}` is assignable to `Record<string,
|
|
717
|
+
//=> '✅ `{}` is assignable to `Record<string, never>`'
|
|
509
718
|
|
|
510
|
-
type Keyed = {} extends Record<'foo' | 'bar',
|
|
511
|
-
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\',
|
|
512
|
-
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\',
|
|
719
|
+
type Keyed = {} extends Record<'foo' | 'bar', never>
|
|
720
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', never>`'
|
|
721
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', never>`';
|
|
513
722
|
|
|
514
723
|
type KeyedResult = Keyed;
|
|
515
|
-
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\',
|
|
724
|
+
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', never>`'
|
|
516
725
|
```
|
|
517
726
|
|
|
518
727
|
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
@@ -524,15 +733,15 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
524
733
|
};
|
|
525
734
|
```
|
|
526
735
|
|
|
527
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType,
|
|
736
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, never>`)...
|
|
528
737
|
|
|
529
738
|
```
|
|
530
739
|
type OmitIndexSignature<ObjectType> = {
|
|
531
740
|
[KeyType in keyof ObjectType
|
|
532
|
-
// Is `{}` assignable to `Record<KeyType,
|
|
533
|
-
as {} extends Record<KeyType,
|
|
534
|
-
? never // ✅ `{}` is assignable to `Record<KeyType,
|
|
535
|
-
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType,
|
|
741
|
+
// Is `{}` assignable to `Record<KeyType, never>`?
|
|
742
|
+
as {} extends Record<KeyType, never>
|
|
743
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, never>`
|
|
744
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, never>`
|
|
536
745
|
]: ObjectType[KeyType];
|
|
537
746
|
};
|
|
538
747
|
```
|
|
@@ -566,9 +775,9 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
566
775
|
@see {@link PickIndexSignature}
|
|
567
776
|
@category Object
|
|
568
777
|
*/
|
|
569
|
-
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType,
|
|
778
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, never> ? never : KeyType]: ObjectType[KeyType]; };
|
|
570
779
|
//#endregion
|
|
571
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
780
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
572
781
|
/**
|
|
573
782
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
574
783
|
|
|
@@ -614,137 +823,261 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
614
823
|
@see {@link OmitIndexSignature}
|
|
615
824
|
@category Object
|
|
616
825
|
*/
|
|
617
|
-
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType,
|
|
826
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, never> ? KeyType : never]: ObjectType[KeyType]; };
|
|
827
|
+
//#endregion
|
|
828
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/internal/keys.d.ts
|
|
829
|
+
/**
|
|
830
|
+
Projects the selected keys as required properties, preserving readonly modifiers.
|
|
831
|
+
*/
|
|
832
|
+
type RequireAll<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]-?: ObjectType[Key]; };
|
|
618
833
|
//#endregion
|
|
619
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
620
|
-
// Merges two objects without worrying about index signatures.
|
|
621
|
-
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key]; } & Source>;
|
|
834
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/internal/object.d.ts
|
|
622
835
|
/**
|
|
623
|
-
|
|
836
|
+
Flatten an object type. This is the plain definition `Simplify` had before it started returning a function, a class constructor, or a branded primitive as is.
|
|
624
837
|
|
|
625
|
-
|
|
838
|
+
Internal types use this instead of `Simplify`, because they only flatten object types they built themselves, where any call signature is already dropped or handled separately and no branded primitive can appear, so they do not need that check. Use `Simplify` if the input can be a function, a class constructor, or a branded primitive. Keeping the check out of them avoids its cost in every type that flattens its result, and avoids the risk of "excessively deep" errors in user code, which a conditional in `Simplify` once caused for types like `SetRequired`. See https://github.com/sindresorhus/type-fest/issues/436.
|
|
839
|
+
*/
|
|
840
|
+
type SimplifyObject<Type> = { [KeyType in keyof Type]: Type[KeyType]; } & {};
|
|
841
|
+
/**
|
|
842
|
+
Normalize keys by including string and number representations wherever applicable.
|
|
626
843
|
|
|
627
844
|
@example
|
|
845
|
+
```ts
|
|
846
|
+
type A = NormalizedKeys<0 | '1'>;
|
|
847
|
+
//=> 0 | '0' | 1 | '1'
|
|
848
|
+
|
|
849
|
+
type B = NormalizedKeys<string>;
|
|
850
|
+
//=> string | number
|
|
851
|
+
|
|
852
|
+
type C = NormalizedKeys<number>;
|
|
853
|
+
//=> number | `${number}`
|
|
854
|
+
|
|
855
|
+
type D = NormalizedKeys<symbol | 'foo'>;
|
|
856
|
+
//=> symbol | 'foo'
|
|
628
857
|
```
|
|
629
|
-
|
|
858
|
+
*/
|
|
859
|
+
type NormalizedKeys<Keys extends PropertyKey> = Keys | (string extends Keys ? number : never) | StringToNumber<Keys & string> | KeyToString<Keys & number>;
|
|
860
|
+
/**
|
|
861
|
+
Get the given keys with their numeric and string aliases, including the runtime string spelling of enum keys.
|
|
630
862
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
863
|
+
@example
|
|
864
|
+
```ts
|
|
865
|
+
enum Color {
|
|
866
|
+
Red = 'red',
|
|
867
|
+
}
|
|
635
868
|
|
|
636
|
-
type
|
|
637
|
-
|
|
638
|
-
|
|
869
|
+
type A = KeyAliases<0 | Color.Red>;
|
|
870
|
+
//=> 0 | '0' | Color.Red | 'red'
|
|
871
|
+
```
|
|
872
|
+
*/
|
|
873
|
+
type KeyAliases<Keys extends PropertyKey> = NormalizedKeys<Keys | KeyToString<Keys>>;
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/required-keys-of.d.ts
|
|
876
|
+
/**
|
|
877
|
+
Extract all required keys from the given type.
|
|
878
|
+
|
|
879
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
880
|
+
|
|
881
|
+
@example
|
|
882
|
+
```
|
|
883
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
884
|
+
|
|
885
|
+
declare function createValidation<
|
|
886
|
+
Entity extends object,
|
|
887
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
888
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
889
|
+
|
|
890
|
+
type User = {
|
|
891
|
+
name: string;
|
|
892
|
+
surname: string;
|
|
893
|
+
luckyNumber?: number;
|
|
639
894
|
};
|
|
640
895
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
//=> never
|
|
896
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
897
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
644
898
|
|
|
645
|
-
//
|
|
646
|
-
|
|
647
|
-
|
|
899
|
+
// @ts-expect-error
|
|
900
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
901
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
648
902
|
```
|
|
649
903
|
|
|
904
|
+
Known limitations:
|
|
905
|
+
- An index signature is reported as a required key, so `RequiredKeysOf<Record<string, unknown>>` is `string` rather than `never`. The signature satisfies the required-property check against `Record<Key, Type[Key]>`, even though no particular property has to be present.
|
|
906
|
+
- A union reports the keys of each of its members, so the result can name a key that is not a key of the union itself. `keyof` of a union is the intersection of its members' keys, so `RequiredKeysOf<{a: string} | {b: number}>` is `'a' | 'b'` while `keyof` of the same union is `never`. Read one member at a time if you need a key that is valid for the whole union.
|
|
907
|
+
|
|
908
|
+
@category Utilities
|
|
909
|
+
*/
|
|
910
|
+
type RequiredKeysOf<Type extends object> = IsAny<Type> extends true ? keyof Type : Type extends unknown // For distributing `Type`
|
|
911
|
+
? (keyof { [Key in keyof Type as Type extends Record<Key, Type[Key]> ? Key : never]: never; }) & keyof Type : never; // Should never happen
|
|
912
|
+
//#endregion
|
|
913
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/merge.d.ts
|
|
914
|
+
type _Merge<Destination, Source> =
|
|
915
|
+
// The mapped types in `MergeObjects` drop call signatures, so the source's call signature, or else the destination's, is added back. Each branch has its own intersection, so that tooltips show the result rather than `_Merge`.
|
|
916
|
+
unknown extends CallSignatureOf<Source> ? CallSignatureOf<Destination> & MergeObjects<Destination, Source> : CallSignatureOf<Source> & MergeObjects<Destination, Source>;
|
|
917
|
+
// Numeric properties, enum keys, and their string forms name the same property, so normalize the source's named keys before testing overrides.
|
|
918
|
+
// Merges the properties and index signatures of two objects. A key of the destination is dropped when the source overrides it: an index signature only by an index signature, and a property only by a property. The destination is read only once, because each extra read multiplies the work of nested merges, such as in `MergeAll`. The source is rebuilt with key remapping instead of intersected as is, because an intersection with an `any` source is `any`, which loses the properties of the destination.
|
|
919
|
+
type MergeObjects<Destination, Source> = SimplifyObject<{ [Key in keyof Destination as {} extends Record<Key, never> ? Key extends keyof PickIndexSignature<Source> ? never : Key : Key extends KeyAliases<keyof OmitIndexSignature<Source>> ? never : Key]: Destination[Key]; } & { [Key in keyof Source as Key]: Source[Key]; }>;
|
|
920
|
+
//#endregion
|
|
921
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/apply-default-options.d.ts
|
|
922
|
+
/**
|
|
923
|
+
Apply default options to specified options, preserving literal types.
|
|
924
|
+
|
|
925
|
+
Useful for authors of configurable utility types. `Defaults` must give every optional option a default and must not give a default for a required option. Each default must be assignable to its option type. `SpecifiedOptions` must satisfy `Options`, including its required properties. Use {@link DefaultsFor} to define a defaults object.
|
|
926
|
+
|
|
927
|
+
The resolution is shallow, so a nested object is replaced as a whole. A specified option overrides its default. An optional or `undefined`-including specified option uses the default when the declared type does not admit `undefined`, and still overrides when the declared type admits `undefined`, such as `unknown` or `string | undefined`. A numeric key can use either spelling, so `0` and `'0'` name the same option. Every option declared in `Options` is required, and its `readonly` modifier comes from the chosen default or override.
|
|
928
|
+
|
|
650
929
|
@example
|
|
651
930
|
```
|
|
652
|
-
import type {
|
|
931
|
+
import type {ApplyDefaultOptions} from 'type-fest';
|
|
653
932
|
|
|
654
|
-
type
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
foo: string;
|
|
658
|
-
bar: symbol;
|
|
933
|
+
type FormatOptions = {
|
|
934
|
+
uppercase?: boolean;
|
|
935
|
+
prefix?: string;
|
|
659
936
|
};
|
|
660
937
|
|
|
661
|
-
type
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
bar: Date;
|
|
665
|
-
baz: boolean;
|
|
938
|
+
type DefaultFormatOptions = {
|
|
939
|
+
uppercase: false;
|
|
940
|
+
prefix: '';
|
|
666
941
|
};
|
|
667
942
|
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
943
|
+
type Format<Value extends string, Options extends FormatOptions = {}> = FormatWithOptions<Value, ApplyDefaultOptions<FormatOptions, DefaultFormatOptions, Options>>;
|
|
944
|
+
|
|
945
|
+
type FormatWithOptions<Value extends string, Options extends Required<FormatOptions>> = `${Options['prefix']}${Options['uppercase'] extends true ? Uppercase<Value> : Value}`;
|
|
946
|
+
|
|
947
|
+
type Plain = Format<'hello'>;
|
|
948
|
+
//=> 'hello'
|
|
949
|
+
|
|
950
|
+
type Heading = Format<'hello', {uppercase: true; prefix: '# '}>;
|
|
951
|
+
//=> '# HELLO'
|
|
952
|
+
|
|
953
|
+
type Resolved = ApplyDefaultOptions<FormatOptions, DefaultFormatOptions, {uppercase?: true}>;
|
|
954
|
+
//=> {uppercase: false; prefix: ''}
|
|
677
955
|
```
|
|
678
956
|
|
|
679
|
-
|
|
957
|
+
Known limitations:
|
|
958
|
+
- Intended for an object with named properties. Arrays, tuples, and functions are not supported. A string index signature on `Options` blocks defaults for its named options.
|
|
959
|
+
- A union of option types or a union-valued option uses one resolution, usually the defaults. A `never` option value is not supported.
|
|
960
|
+
- Extra properties are allowed: an extra specified property is kept unless it can be `undefined`, and extra `Defaults` keys are kept.
|
|
961
|
+
- With `any` or `never` as `SpecifiedOptions`, the defaults are used, or `never` if `Options` has a required property.
|
|
962
|
+
- This does not model runtime object spread, so TypeScript may require concrete specified options instead of unresolved generics.
|
|
680
963
|
|
|
681
|
-
@see {@link
|
|
964
|
+
@see {@link DefaultsFor}
|
|
682
965
|
@category Object
|
|
683
966
|
*/
|
|
684
|
-
type
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
967
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends SimplifyObject<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> =
|
|
968
|
+
// Keep the resolved type assignable to `Required<Options>` without inferring a result that can widen a specified generic value to its constraint.
|
|
969
|
+
_ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> extends Required<Options> ? _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> : never;
|
|
970
|
+
type _ApplyDefaultOptions<Options extends object, Defaults, SpecifiedOptions> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults,
|
|
971
|
+
// The overrides are already an object map, so skip `Merge`'s array and equality dispatch.
|
|
972
|
+
_Merge<Defaults, { [
|
|
973
|
+
// The first `as` branch keeps the key of an option whose declared type admits `undefined`, like `unknown`, because `undefined` is one of its valid values. `-?` then strips the optional modifier, so an unnarrowed options type still resolves instead of failing the `Required<Options>` guard above.
|
|
974
|
+
Key in keyof SpecifiedOptions as undefined extends Required<Options>[MatchingKey<Options, Key>] ? Key : undefined extends SpecifiedOptions[Key] ? never : Key]-?: SpecifiedOptions[Key]; }>>>;
|
|
689
975
|
//#endregion
|
|
690
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
976
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/internal/type.d.ts
|
|
691
977
|
/**
|
|
692
|
-
|
|
978
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
693
979
|
|
|
694
980
|
@example
|
|
695
981
|
```
|
|
696
|
-
|
|
697
|
-
type
|
|
698
|
-
|
|
982
|
+
// When `T` is neither `any` nor `never` (like `string`) => Returns the `ifNot` branch
|
|
983
|
+
type A = IfNotAnyOrNever<string, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
984
|
+
//=> 'VALID'
|
|
985
|
+
|
|
986
|
+
// When `T` is `any` => Returns the `ifAny` branch
|
|
987
|
+
type B = IfNotAnyOrNever<any, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
988
|
+
//=> 'IS_ANY'
|
|
699
989
|
|
|
700
|
-
|
|
701
|
-
|
|
990
|
+
// When `T` is `never` => Returns the `ifNever` branch
|
|
991
|
+
type C = IfNotAnyOrNever<never, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
992
|
+
//=> 'IS_NEVER'
|
|
702
993
|
```
|
|
703
994
|
|
|
995
|
+
Note: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:
|
|
996
|
+
|
|
704
997
|
@example
|
|
705
|
-
```
|
|
706
|
-
|
|
998
|
+
```ts
|
|
999
|
+
import type {StringRepeat} from 'type-fest';
|
|
707
1000
|
|
|
708
|
-
type
|
|
709
|
-
|
|
710
|
-
|
|
1001
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
1002
|
+
|
|
1003
|
+
// The following implementation is not tail recursive
|
|
1004
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, {ifNot: S extends ` ${infer R}` ? TrimLeft<R> : S}>;
|
|
1005
|
+
|
|
1006
|
+
// Hence, instantiations with long strings will fail
|
|
1007
|
+
// @ts-expect-error
|
|
1008
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
1009
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1010
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
711
1011
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
1012
|
+
// To fix this, move the recursion into a helper type
|
|
1013
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, {ifNot: _TrimLeftOptimised<S>}>;
|
|
1014
|
+
|
|
1015
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
1016
|
+
|
|
1017
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
1018
|
+
//=> ''
|
|
715
1019
|
```
|
|
1020
|
+
*/
|
|
1021
|
+
type IfNotAnyOrNever<T, Cases extends {
|
|
1022
|
+
ifNot: unknown;
|
|
1023
|
+
ifAny?: unknown;
|
|
1024
|
+
ifNever?: unknown;
|
|
1025
|
+
}> = IsAny<T> extends true ? 'ifAny' extends keyof Cases ? Cases['ifAny'] : any : IsNever<T> extends true ? 'ifNever' extends keyof Cases ? Cases['ifNever'] : never : Cases['ifNot'];
|
|
1026
|
+
/**
|
|
1027
|
+
The call signature of the given type, rebuilt with its `this` parameter, which `Parameters` leaves out, so the rebuilt signature does not accept any receiver. A function that declares no `this` is rebuilt without one, like `OmitThisParameter` does, because `this: unknown` would reject a function that declares a `this`. `unknown` for a type that is not callable, so it can be intersected with anything.
|
|
1028
|
+
|
|
1029
|
+
Readonly rest parameters are preserved.
|
|
1030
|
+
|
|
1031
|
+
Note: An overloaded function keeps only its last signature, and a generic one loses its type parameters.
|
|
1032
|
+
*/
|
|
1033
|
+
type CallSignatureOf<Type> = Type extends ((this: infer Receiver, ...arguments_: infer Arguments extends UnknownArray) => infer Return) ? unknown extends Receiver ? (...arguments_: Arguments) => Return : (this: Receiver, ...arguments_: Arguments) => Return : unknown;
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/require-none.d.ts
|
|
1036
|
+
/**
|
|
1037
|
+
Create an object type that forbids the given keys, to intersect with another object type.
|
|
1038
|
+
|
|
1039
|
+
Use it to reject removed options, or to forbid keys on a generic object type, which {@link Except} cannot do because it only accepts keys of the object type. This does not remove properties from the other type.
|
|
1040
|
+
|
|
1041
|
+
Uses optional `never` properties. With `exactOptionalPropertyTypes` enabled, named keys cannot be supplied, even as `undefined`.
|
|
716
1042
|
|
|
717
1043
|
@example
|
|
718
1044
|
```
|
|
719
|
-
|
|
1045
|
+
import type {RequireNone} from 'type-fest';
|
|
1046
|
+
|
|
1047
|
+
type DeprecatedOptions = RequireNone<'legacyMode' | 'callback'>;
|
|
1048
|
+
//=> {legacyMode?: never; callback?: never}
|
|
720
1049
|
|
|
721
|
-
type
|
|
722
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
723
|
-
type SpecifiedOptions = {};
|
|
1050
|
+
type Options = {url: string} & DeprecatedOptions;
|
|
724
1051
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
//
|
|
1052
|
+
const options: Options = {url: 'https://example.com'};
|
|
1053
|
+
|
|
1054
|
+
// @ts-expect-error
|
|
1055
|
+
const deprecated: Options = {url: 'https://example.com', legacyMode: true};
|
|
728
1056
|
```
|
|
729
1057
|
|
|
730
1058
|
@example
|
|
731
1059
|
```
|
|
732
|
-
|
|
1060
|
+
import type {RequireNone} from 'type-fest';
|
|
1061
|
+
|
|
1062
|
+
// The database creates the `id`, so a new row must not have one.
|
|
1063
|
+
declare function insert<Row extends object>(row: Row & RequireNone<'id'>): void;
|
|
733
1064
|
|
|
734
|
-
|
|
735
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
736
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1065
|
+
insert({name: 'Alice'});
|
|
737
1066
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1067
|
+
// @ts-expect-error
|
|
1068
|
+
insert({id: 1, name: 'Alice'});
|
|
741
1069
|
```
|
|
1070
|
+
|
|
1071
|
+
Note: `RequireNone<never>` produces `{}`, which does not enforce an empty object. Broad keys (`string`, `number`, `symbol`, or template literal patterns) produce index signatures that allow `undefined` values. Properties absent from a value's static type cannot be checked.
|
|
1072
|
+
|
|
1073
|
+
@see {@link Except} with `{requireExactProps: true}` to remove keys from an object type and forbid them.
|
|
1074
|
+
@see {@link MergeExclusive} or {@link ExclusifyUnion} to make object types mutually exclusive.
|
|
1075
|
+
|
|
1076
|
+
@category Object
|
|
742
1077
|
*/
|
|
743
|
-
type
|
|
744
|
-
) ? Result : never;
|
|
745
|
-
type _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Merge<Defaults, { [Key in keyof SpecifiedOptions as undefined extends Required<Options>[Key & keyof Options] ? Key : undefined extends SpecifiedOptions[Key] ? never : Key]: SpecifiedOptions[Key]; }>>>;
|
|
1078
|
+
type RequireNone<KeysType extends PropertyKey> = { [Key in KeysType]?: never; };
|
|
746
1079
|
//#endregion
|
|
747
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
1080
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/except.d.ts
|
|
748
1081
|
/**
|
|
749
1082
|
Filter out keys from an object.
|
|
750
1083
|
|
|
@@ -772,7 +1105,7 @@ type Filtered = Filter<'bar', 'foo'>;
|
|
|
772
1105
|
|
|
773
1106
|
@see {Except}
|
|
774
1107
|
*/
|
|
775
|
-
type Filter<KeyType, ExcludeType> =
|
|
1108
|
+
type Filter<KeyType, ExcludeType> = Exclude<KeyType, ExcludeType>;
|
|
776
1109
|
type ExceptOptions = {
|
|
777
1110
|
/**
|
|
778
1111
|
Disallow assigning non-specified properties.
|
|
@@ -795,6 +1128,8 @@ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/
|
|
|
795
1128
|
|
|
796
1129
|
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
797
1130
|
|
|
1131
|
+
Note: For a generic conditional type, TypeScript only accepts the keys that all its branches share, because it does not know which branch applies. To remove a key that only some branches have, intersect it with `KeysOfUnion`, as in `Except<Conditional<T>, 'key' & KeysOfUnion<Conditional<T>>>`. When the resolved type does not have the key, nothing is removed.
|
|
1132
|
+
|
|
798
1133
|
@example
|
|
799
1134
|
```
|
|
800
1135
|
import type {Except} from 'type-fest';
|
|
@@ -812,7 +1147,7 @@ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
|
812
1147
|
// errors: 'a' does not exist in type '{ b: string; }'
|
|
813
1148
|
|
|
814
1149
|
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
815
|
-
//=> {a: number} &
|
|
1150
|
+
//=> {a: number} & {b?: never}
|
|
816
1151
|
|
|
817
1152
|
// @ts-expect-error
|
|
818
1153
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
@@ -841,13 +1176,20 @@ type PostPayloadFixed = Except<UserData, 'email'>;
|
|
|
841
1176
|
|
|
842
1177
|
@category Object
|
|
843
1178
|
*/
|
|
844
|
-
type Except<ObjectType, KeysType extends
|
|
845
|
-
type
|
|
1179
|
+
type Except<ObjectType, KeysType extends KeysOfUnion<ObjectType>, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
1180
|
+
// The mapped type is homomorphic, so it distributes over a union `ObjectType` by itself, and a generic `ObjectType` stays assignable to it. Only `requireExactProps` needs an explicit distribution, so that each member gets its own keys.
|
|
1181
|
+
type _Except<ObjectType, KeysType, Options extends Required<ExceptOptions>> = Options['requireExactProps'] extends true ? ObjectType extends unknown ? { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType]; } & RequireNone<KeysType & keyof ObjectType> : never : { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType]; };
|
|
846
1182
|
//#endregion
|
|
847
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
1183
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/require-at-least-one.d.ts
|
|
848
1184
|
/**
|
|
849
1185
|
Create a type that requires at least one of the given keys, while keeping the remaining keys as is.
|
|
850
1186
|
|
|
1187
|
+
Note: For a union, a member that has none of the given keys is kept as it is. For example, with `{kind: 'circle'; radius?: number; diameter?: number} | {kind: 'square'; side: number}` and the keys `'radius' | 'diameter'`, a square needs neither key.
|
|
1188
|
+
|
|
1189
|
+
Note: An index signature cannot be required, so if the keys include one (for example, the default keys of `Record<string, number>`), the type accepts `{}`.
|
|
1190
|
+
|
|
1191
|
+
Note: A check of a key for `undefined` does not narrow the type, because TypeScript only narrows a union through a property with a literal type. For example, with `{a: string; b: string}`, `value.a ?? value.b` is `string | undefined`. Use the `in` operator instead: `'a' in value ? value.a : value.b`.
|
|
1192
|
+
|
|
851
1193
|
@example
|
|
852
1194
|
```
|
|
853
1195
|
import type {RequireAtLeastOne} from 'type-fest';
|
|
@@ -866,14 +1208,18 @@ const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
|
866
1208
|
|
|
867
1209
|
@category Object
|
|
868
1210
|
*/
|
|
869
|
-
type RequireAtLeastOne<ObjectType, KeysType extends
|
|
870
|
-
ifNot: If<IsNever<KeysType>, never, _RequireAtLeastOne<ObjectType, If<IsAny<KeysType>,
|
|
1211
|
+
type RequireAtLeastOne<ObjectType, KeysType extends KeysOfUnion<ObjectType> = KeysOfUnion<ObjectType>> = IfNotAnyOrNever<ObjectType, {
|
|
1212
|
+
ifNot: If<IsNever<KeysType>, never, _RequireAtLeastOne<ObjectType, If<IsAny<KeysType>, KeysOfUnion<ObjectType>, KeysType>>>;
|
|
871
1213
|
}>;
|
|
872
|
-
|
|
1214
|
+
// The keys are intersected with each member's own inside the distribution, because `keyof` of a union is the intersection of its members' keys, so a key only one member has would otherwise be dropped before the mapped type ever saw it.
|
|
1215
|
+
type _RequireAtLeastOne<ObjectType, KeysType> = ObjectType extends unknown ?
|
|
1216
|
+
// A member that has none of the keys is left as it is.
|
|
1217
|
+
If<IsNever<KeysType & keyof ObjectType>, ObjectType, _RequireAtLeastOneOfOne<ObjectType, KeysType & keyof ObjectType>> : never;
|
|
1218
|
+
type _RequireAtLeastOneOfOne<ObjectType, KeysType extends keyof ObjectType> = { [
|
|
873
1219
|
// For each `Key` in `KeysType` make a mapped type:
|
|
874
|
-
Key in KeysType]-?:
|
|
875
|
-
&
|
|
876
|
-
|
|
1220
|
+
Key in KeysType]-?: RequireAll<ObjectType, Key> // 1. Make `Key`'s type required
|
|
1221
|
+
; }[KeysType] & { [Key in KeysType]?: ObjectType[Key]; } // 2. Share the optional selected fields; each alternative's required key overrides its optional copy.
|
|
1222
|
+
& Except<ObjectType, KeysType>; // 3. Add the remaining keys not in `KeysType`
|
|
877
1223
|
//#endregion
|
|
878
1224
|
//#region src-js/plugins/tokens.d.ts
|
|
879
1225
|
/**
|
|
@@ -1005,7 +1351,7 @@ interface ObjectProperty extends Span {
|
|
|
1005
1351
|
optional?: false;
|
|
1006
1352
|
parent: Node$1;
|
|
1007
1353
|
}
|
|
1008
|
-
type PropertyKey$1 = IdentifierName | PrivateIdentifier | Expression;
|
|
1354
|
+
type PropertyKey$1 = IdentifierName | StringLiteral | NumericLiteral | BigIntLiteral | PrivateIdentifier | Expression;
|
|
1009
1355
|
type PropertyKind = "init" | "get" | "set";
|
|
1010
1356
|
interface TemplateLiteral extends Span {
|
|
1011
1357
|
type: "TemplateLiteral";
|
|
@@ -3253,6 +3599,7 @@ interface Context extends FileContext {
|
|
|
3253
3599
|
*/
|
|
3254
3600
|
report(this: void, diagnostic: Diagnostic): void;
|
|
3255
3601
|
}
|
|
3602
|
+
type DecisionModel = "typesafe/jev-latest" | `typesafe/jev-${number}.${number}` | "cloudflare/@cf/cloudflare/clef" | "cloudflare/@cf/cloudflare/clef-flash" | "cloudflare/@cf/cloudflare/clef-omni";
|
|
3256
3603
|
declare const TargetSchema: Schema.Literals<readonly ["function", "call", "jsx", "file"]>;
|
|
3257
3604
|
declare const CiBehaviorSchema: Schema.Literals<readonly ["skip", "fail"]>;
|
|
3258
3605
|
declare const ExplainSettingSchema: Schema.Union<readonly [Schema.Boolean, Schema.Literals<readonly ["text", "json"]>]>;
|
|
@@ -3286,7 +3633,7 @@ interface SelectMatch {
|
|
|
3286
3633
|
}
|
|
3287
3634
|
type Target = typeof TargetSchema.Type;
|
|
3288
3635
|
type CiBehavior = typeof CiBehaviorSchema.Type;
|
|
3289
|
-
type ModelSpec =
|
|
3636
|
+
type ModelSpec = DecisionModel | readonly DecisionModel[];
|
|
3290
3637
|
type ExplainSetting = typeof ExplainSettingSchema.Type;
|
|
3291
3638
|
interface RuleLocation {
|
|
3292
3639
|
readonly question: string;
|
|
@@ -3316,47 +3663,42 @@ interface DecisionOptions {
|
|
|
3316
3663
|
readonly env?: Readonly<Record<string, string>>;
|
|
3317
3664
|
readonly explain?: ExplainSetting;
|
|
3318
3665
|
}
|
|
3319
|
-
interface NoulQuestion
|
|
3666
|
+
interface NoulQuestion {
|
|
3667
|
+
readonly type: "noul";
|
|
3320
3668
|
readonly instructions: string;
|
|
3321
3669
|
}
|
|
3322
|
-
interface ChoiceQuestion
|
|
3670
|
+
interface ChoiceQuestion {
|
|
3671
|
+
readonly type: "choice";
|
|
3323
3672
|
readonly instructions: string;
|
|
3324
3673
|
readonly criteria: Readonly<Record<string, string | null>>;
|
|
3325
3674
|
}
|
|
3326
|
-
type Question = NoulQuestion
|
|
3327
|
-
interface DecisionRequest
|
|
3675
|
+
type Question = NoulQuestion | ChoiceQuestion;
|
|
3676
|
+
interface DecisionRequest {
|
|
3677
|
+
readonly model: string;
|
|
3328
3678
|
readonly state: {
|
|
3329
3679
|
readonly snippets: Readonly<Record<string, string>>;
|
|
3330
3680
|
readonly contexts?: Readonly<Record<string, string>>;
|
|
3331
3681
|
};
|
|
3332
3682
|
readonly questions: Readonly<Record<string, Question>>;
|
|
3333
3683
|
}
|
|
3334
|
-
|
|
3335
|
-
type
|
|
3336
|
-
readonly
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
readonly
|
|
3341
|
-
readonly
|
|
3342
|
-
}
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
readonly
|
|
3347
|
-
|
|
3348
|
-
interface DecisionProvider {
|
|
3349
|
-
readonly name: string;
|
|
3350
|
-
readonly requiredEnv: readonly string[];
|
|
3351
|
-
readonly models?: RegExp;
|
|
3352
|
-
readonly yesNo?: boolean;
|
|
3353
|
-
readonly decide: (input: DecideInput) => DecideResult;
|
|
3354
|
-
readonly decideAll?: (inputs: readonly DecideInput[]) => readonly DecideResult[];
|
|
3684
|
+
interface NoulAnswer {
|
|
3685
|
+
readonly type: "noul";
|
|
3686
|
+
readonly noul: number;
|
|
3687
|
+
}
|
|
3688
|
+
interface ChoiceAnswer {
|
|
3689
|
+
readonly type: "choice";
|
|
3690
|
+
readonly choice: string;
|
|
3691
|
+
readonly probabilities?: Readonly<Record<string, number>> | undefined;
|
|
3692
|
+
}
|
|
3693
|
+
type Answer = NoulAnswer | ChoiceAnswer;
|
|
3694
|
+
type Answers = Readonly<Record<string, Answer>>;
|
|
3695
|
+
interface DecisionResponse {
|
|
3696
|
+
readonly model: string;
|
|
3697
|
+
readonly answers: Answers;
|
|
3355
3698
|
}
|
|
3356
3699
|
interface DecisionPluginSetup extends DecisionOptions {
|
|
3357
3700
|
readonly name?: string;
|
|
3358
3701
|
readonly rules: readonly DecisionRule[];
|
|
3359
|
-
readonly providers?: readonly DecisionProvider[];
|
|
3360
3702
|
}
|
|
3361
3703
|
interface DecisionPlugin {
|
|
3362
3704
|
readonly meta: {
|
|
@@ -3365,6 +3707,6 @@ interface DecisionPlugin {
|
|
|
3365
3707
|
readonly rules: Readonly<Record<string, object>>;
|
|
3366
3708
|
}
|
|
3367
3709
|
declare const defineDecisionRule: <const Rule extends DecisionRule>(rule: Rule) => Rule;
|
|
3368
|
-
declare const
|
|
3369
|
-
export {
|
|
3370
|
-
//# sourceMappingURL=index-
|
|
3710
|
+
declare const createDecisionPlugin: (setup: DecisionPluginSetup) => DecisionPlugin;
|
|
3711
|
+
export { Target as C, Severity as S, RuleAnswer as _, DecisionOptions as a, SelectMatch as b, DecisionRequest as c, EnclosingKind as d, ExplainSetting as f, Question as g, NoulQuestion as h, CiBehavior as i, DecisionResponse as l, ModelSpec as m, defineDecisionRule as n, DecisionPlugin as o, Frozen as p, ChoiceQuestion as r, DecisionPluginSetup as s, createDecisionPlugin as t, DecisionRule as u, RuleContext as v, DecisionModel as w, SelectedNode as x, RuleLocation as y };
|
|
3712
|
+
//# sourceMappingURL=index-CK88FBE5.d.mts.map
|