@r_masseater/oxlint-plugin-decision 0.8.0 → 0.8.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/README.md +5 -0
- package/dist/{app-UakaWKAT.mjs → app-D2bguKZ_.mjs} +137 -27
- 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 -2
- package/dist/cloudflare-worker.mjs.map +1 -1
- package/dist/{index-HOwrGbIA.d.mts → index-B4wX62VC.d.mts} +2 -2
- package/dist/{index-C0Twu0w7.d.mts → index-CK88FBE5.d.mts} +666 -319
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{define-presets-yflVt8vT.mjs → preset-plugin-MKdvpXxa.mjs} +11 -214
- package/dist/preset-plugin-MKdvpXxa.mjs.map +1 -0
- package/dist/presets/ai-slop.d.mts +2 -2
- 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 -1
- package/dist/presets/recommended.mjs +1 -2
- package/dist/presets/recommended.mjs.map +1 -1
- package/dist/presets/review-only.d.mts +1 -1
- package/dist/presets/review-only.mjs +1 -2
- package/dist/presets/review-only.mjs.map +1 -1
- package/dist/presets/strict.d.mts +1 -1
- 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 +20 -2
- package/dist/typesafe-worker.mjs.map +1 -1
- package/dist/{decision-B7hahWHz.mjs → wire-CKpt_MBX.mjs} +11 -134
- package/dist/wire-CKpt_MBX.mjs.map +1 -0
- package/package.json +23 -21
- package/skills/write-decision-rules/SKILL.md +0 -1
- package/skills/write-decision-rules/references/tuning.md +2 -2
- package/dist/app-UakaWKAT.mjs.map +0 -1
- package/dist/decision-B7hahWHz.mjs.map +0 -1
- package/dist/define-presets-yflVt8vT.mjs.map +0 -1
- package/dist/preset-plugin-ClpEFUN5.mjs +0 -10
- package/dist/preset-plugin-ClpEFUN5.mjs.map +0 -1
- package/dist/serve-decisions-DYGwLMft.mjs +0 -287
- package/dist/serve-decisions-DYGwLMft.mjs.map +0 -1
|
@@ -33,11 +33,67 @@ type JsonObject = {
|
|
|
33
33
|
*/
|
|
34
34
|
type Options = JsonValue[];
|
|
35
35
|
//#endregion
|
|
36
|
-
//#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
|
|
37
91
|
/**
|
|
38
92
|
Returns a boolean for whether the given type is `any`.
|
|
39
93
|
|
|
40
|
-
|
|
94
|
+
Returns `false` for `never` and `unknown`. Unions are normalized before the check.
|
|
95
|
+
|
|
96
|
+
@see https://stackoverflow.com/a/49928360/1490091
|
|
41
97
|
|
|
42
98
|
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
43
99
|
|
|
@@ -64,178 +120,344 @@ const anyA = get(anyObject, 'a');
|
|
|
64
120
|
*/
|
|
65
121
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
66
122
|
//#endregion
|
|
67
|
-
//#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
|
|
68
124
|
/**
|
|
69
|
-
Returns a boolean for whether the given
|
|
125
|
+
Returns a boolean for whether the given type is `never`.
|
|
70
126
|
|
|
71
|
-
|
|
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.
|
|
72
132
|
|
|
73
133
|
@example
|
|
74
134
|
```
|
|
75
|
-
import type {
|
|
76
|
-
|
|
77
|
-
type User = {
|
|
78
|
-
name: string;
|
|
79
|
-
surname: string;
|
|
135
|
+
import type {IsNever, And} from 'type-fest';
|
|
80
136
|
|
|
81
|
-
|
|
82
|
-
|
|
137
|
+
type A = IsNever<never>;
|
|
138
|
+
//=> true
|
|
83
139
|
|
|
84
|
-
type
|
|
85
|
-
|
|
86
|
-
surname?: string;
|
|
87
|
-
};
|
|
140
|
+
type B = IsNever<any>;
|
|
141
|
+
//=> false
|
|
88
142
|
|
|
89
|
-
type
|
|
90
|
-
//=>
|
|
143
|
+
type C = IsNever<unknown>;
|
|
144
|
+
//=> false
|
|
91
145
|
|
|
92
|
-
type
|
|
146
|
+
type D = IsNever<never[]>;
|
|
93
147
|
//=> false
|
|
94
148
|
|
|
95
|
-
type
|
|
96
|
-
//=>
|
|
149
|
+
type E = IsNever<object>;
|
|
150
|
+
//=> false
|
|
97
151
|
|
|
98
|
-
type
|
|
152
|
+
type F = IsNever<string>;
|
|
99
153
|
//=> false
|
|
154
|
+
```
|
|
100
155
|
|
|
101
|
-
|
|
102
|
-
|
|
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;
|
|
169
|
+
|
|
170
|
+
type B = IsTrueFixed<never>;
|
|
171
|
+
//=> false
|
|
103
172
|
```
|
|
104
173
|
|
|
105
174
|
@category Type Guard
|
|
106
175
|
@category Utilities
|
|
107
176
|
*/
|
|
108
|
-
type
|
|
177
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
109
178
|
//#endregion
|
|
110
|
-
//#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
|
|
111
180
|
/**
|
|
112
|
-
|
|
181
|
+
Represents an array with `unknown` value.
|
|
113
182
|
|
|
114
|
-
|
|
183
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
115
184
|
|
|
116
185
|
@example
|
|
117
186
|
```
|
|
118
|
-
import type {
|
|
119
|
-
|
|
120
|
-
type User = {
|
|
121
|
-
name: string;
|
|
122
|
-
surname: string;
|
|
187
|
+
import type {UnknownArray} from 'type-fest';
|
|
123
188
|
|
|
124
|
-
|
|
125
|
-
};
|
|
189
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
126
190
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
130
|
-
};
|
|
191
|
+
type A = IsArray<['foo']>;
|
|
192
|
+
//=> true
|
|
131
193
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
};
|
|
194
|
+
type B = IsArray<readonly number[]>;
|
|
195
|
+
//=> true
|
|
135
196
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
luckyNumber: REMOVE_FIELD,
|
|
139
|
-
};
|
|
197
|
+
type C = IsArray<string>;
|
|
198
|
+
//=> false
|
|
140
199
|
```
|
|
141
200
|
|
|
142
|
-
@category
|
|
201
|
+
@category Type
|
|
202
|
+
@category Array
|
|
143
203
|
*/
|
|
144
|
-
type
|
|
145
|
-
? (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`
|
|
146
|
-
: never; // Should never happen
|
|
204
|
+
type UnknownArray = readonly unknown[];
|
|
147
205
|
//#endregion
|
|
148
|
-
//#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
|
|
149
207
|
/**
|
|
150
|
-
|
|
208
|
+
Collapse literal union members into broader types already present in the union.
|
|
151
209
|
|
|
152
|
-
|
|
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.
|
|
153
213
|
|
|
154
214
|
@example
|
|
155
215
|
```
|
|
156
|
-
import type {
|
|
216
|
+
import type {CollapseLiterals, LiteralUnion} from 'type-fest';
|
|
157
217
|
|
|
158
|
-
|
|
159
|
-
Entity extends object,
|
|
160
|
-
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
161
|
-
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
218
|
+
type Theme = LiteralUnion<'auto' | 'dark', string>;
|
|
162
219
|
|
|
163
|
-
type
|
|
164
|
-
|
|
165
|
-
surname: string;
|
|
166
|
-
luckyNumber?: number;
|
|
167
|
-
};
|
|
220
|
+
type ThemeValue = CollapseLiterals<Theme>;
|
|
221
|
+
//=> string
|
|
168
222
|
|
|
169
|
-
|
|
170
|
-
|
|
223
|
+
type OptionalTheme = CollapseLiterals<Theme | null | undefined>;
|
|
224
|
+
//=> string | null | undefined
|
|
171
225
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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'
|
|
175
234
|
```
|
|
176
235
|
|
|
177
|
-
@
|
|
236
|
+
@see {@link LiteralUnion}
|
|
237
|
+
@see {@link ExtractLiterals}
|
|
238
|
+
@see {@link LiteralToPrimitive}
|
|
239
|
+
@category Type
|
|
178
240
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
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;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region ../../node_modules/.pnpm/tagged-tag@1.0.0/node_modules/tagged-tag/index.d.ts
|
|
246
|
+
declare const tag: unique symbol;
|
|
181
247
|
//#endregion
|
|
182
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
248
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/union-member.d.ts
|
|
183
249
|
/**
|
|
184
|
-
Returns
|
|
250
|
+
Returns an arbitrary member of a union type.
|
|
185
251
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
252
|
+
Use-cases:
|
|
253
|
+
- Implementing recursive type functions that accept a union type.
|
|
189
254
|
|
|
190
|
-
|
|
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
|
|
191
274
|
|
|
192
275
|
@example
|
|
193
276
|
```
|
|
194
|
-
import type {
|
|
277
|
+
import type {UnionMember, Primitive, LiteralToPrimitive} from 'type-fest';
|
|
195
278
|
|
|
196
|
-
type
|
|
279
|
+
type IsHomogenous<T extends Primitive> = [T] extends [LiteralToPrimitive<UnionMember<T>>] ? true : false;
|
|
280
|
+
|
|
281
|
+
type T1 = IsHomogenous<1 | 2 | 3 | 4>;
|
|
197
282
|
//=> true
|
|
198
283
|
|
|
199
|
-
type
|
|
200
|
-
//=>
|
|
284
|
+
type T2 = IsHomogenous<'foo' | 'bar'>;
|
|
285
|
+
//=> true
|
|
201
286
|
|
|
202
|
-
type
|
|
287
|
+
type T3 = IsHomogenous<'foo' | 'bar' | 1>;
|
|
203
288
|
//=> false
|
|
289
|
+
```
|
|
204
290
|
|
|
205
|
-
|
|
206
|
-
//=> false
|
|
291
|
+
Returns `never` when the input is `never`.
|
|
207
292
|
|
|
208
|
-
|
|
209
|
-
|
|
293
|
+
@example
|
|
294
|
+
```
|
|
295
|
+
import type {UnionMember} from 'type-fest';
|
|
210
296
|
|
|
211
|
-
type
|
|
212
|
-
//=>
|
|
297
|
+
type LastNever = UnionMember<never>;
|
|
298
|
+
//=> never
|
|
213
299
|
```
|
|
214
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
|
+
|
|
215
320
|
@example
|
|
216
321
|
```
|
|
217
|
-
import type {
|
|
322
|
+
import type {Tag, Tagged} from 'type-fest';
|
|
218
323
|
|
|
219
|
-
type
|
|
324
|
+
type Url = Tagged<string, 'URL'>;
|
|
325
|
+
type UrlObject = Tagged<URL, 'URL'>;
|
|
220
326
|
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
//=> never
|
|
327
|
+
// Accepts any type that has the `URL` tag, with any metadata.
|
|
328
|
+
declare function fetchUrl(url: Tag<'URL', unknown>): void;
|
|
224
329
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
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);
|
|
228
332
|
|
|
229
|
-
|
|
230
|
-
|
|
333
|
+
// @ts-expect-error
|
|
334
|
+
fetchUrl('https://example.com');
|
|
231
335
|
```
|
|
232
336
|
|
|
233
|
-
@category Type
|
|
234
|
-
@category Utilities
|
|
337
|
+
@category Type
|
|
235
338
|
*/
|
|
236
|
-
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);
|
|
400
|
+
//#endregion
|
|
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;
|
|
237
459
|
//#endregion
|
|
238
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
460
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/if.d.ts
|
|
239
461
|
/**
|
|
240
462
|
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
241
463
|
|
|
@@ -330,150 +552,138 @@ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
|
330
552
|
*/
|
|
331
553
|
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
332
554
|
//#endregion
|
|
333
|
-
//#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
|
|
334
556
|
/**
|
|
335
|
-
|
|
557
|
+
Convert a string or number key to its template literal representation.
|
|
336
558
|
|
|
337
|
-
|
|
338
|
-
```
|
|
339
|
-
// When `T` is neither `any` nor `never` (like `string`) => Returns `IfNot` branch
|
|
340
|
-
type A = IfNotAnyOrNever<string, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
341
|
-
//=> 'VALID'
|
|
559
|
+
Note: This type is not the return type of the `.toString()` function.
|
|
342
560
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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.
|
|
346
568
|
|
|
347
|
-
|
|
348
|
-
type C = IfNotAnyOrNever<never, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
349
|
-
//=> 'IS_NEVER'
|
|
350
|
-
```
|
|
569
|
+
Useful when composing generic property access utilities that accept either `0` or `'0'` for the same property. Returns `never` if no key matches.
|
|
351
570
|
|
|
352
|
-
|
|
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`.
|
|
353
572
|
|
|
354
|
-
|
|
355
|
-
```ts
|
|
356
|
-
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.
|
|
357
574
|
|
|
358
|
-
|
|
575
|
+
@example
|
|
576
|
+
```
|
|
577
|
+
import type {MatchingKey} from 'type-fest';
|
|
359
578
|
|
|
360
|
-
|
|
361
|
-
|
|
579
|
+
type StatusMessages = {
|
|
580
|
+
200: 'OK';
|
|
581
|
+
'404': 'Not found';
|
|
582
|
+
};
|
|
362
583
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
366
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
367
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
584
|
+
type SuccessKey = MatchingKey<StatusMessages, '200'>;
|
|
585
|
+
//=> 200
|
|
368
586
|
|
|
369
|
-
|
|
370
|
-
|
|
587
|
+
type NotFoundKey = MatchingKey<StatusMessages, 404>;
|
|
588
|
+
//=> '404'
|
|
371
589
|
|
|
372
|
-
type
|
|
590
|
+
type PickByKey<ObjectType extends object, Key extends PropertyKey> = Pick<ObjectType, MatchingKey<ObjectType, Key>>;
|
|
373
591
|
|
|
374
|
-
type
|
|
375
|
-
//=> ''
|
|
592
|
+
type Success = PickByKey<StatusMessages, '200'>;
|
|
593
|
+
//=> {200: 'OK'}
|
|
376
594
|
```
|
|
595
|
+
|
|
596
|
+
@see {@link PropertyValue} to get the value of the matching property.
|
|
597
|
+
|
|
598
|
+
@category Object
|
|
377
599
|
*/
|
|
378
|
-
type
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
ifNever?: unknown;
|
|
382
|
-
}> = 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;
|
|
383
603
|
//#endregion
|
|
384
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
604
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/numeric.d.ts
|
|
385
605
|
/**
|
|
386
|
-
|
|
606
|
+
Matches the hidden `Infinity` type.
|
|
387
607
|
|
|
388
|
-
|
|
389
|
-
```
|
|
390
|
-
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.
|
|
391
609
|
|
|
392
|
-
|
|
393
|
-
top: number;
|
|
394
|
-
left: number;
|
|
395
|
-
};
|
|
610
|
+
@see {@link NegativeInfinity}
|
|
396
611
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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.
|
|
401
619
|
|
|
402
|
-
|
|
403
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
404
|
-
```
|
|
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.
|
|
405
621
|
|
|
406
|
-
|
|
622
|
+
@see {@link PositiveInfinity}
|
|
407
623
|
|
|
408
|
-
|
|
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.
|
|
409
633
|
|
|
410
634
|
@example
|
|
411
635
|
```
|
|
412
|
-
import type {
|
|
636
|
+
import type {StringToNumber} from 'type-fest';
|
|
413
637
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
bar?: string;
|
|
417
|
-
baz: number | undefined;
|
|
418
|
-
}
|
|
638
|
+
type PositiveInteger = StringToNumber<'1234'>;
|
|
639
|
+
//=> 1234
|
|
419
640
|
|
|
420
|
-
type
|
|
421
|
-
|
|
422
|
-
bar?: string;
|
|
423
|
-
baz: number | undefined;
|
|
424
|
-
};
|
|
641
|
+
type NegativeInteger = StringToNumber<'-1234'>;
|
|
642
|
+
//=> -1234
|
|
425
643
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const someInterface: SomeInterface = literal;
|
|
644
|
+
type PositiveFloat = StringToNumber<'1234.56'>;
|
|
645
|
+
//=> 1234.56
|
|
429
646
|
|
|
430
|
-
|
|
647
|
+
type NegativeFloat = StringToNumber<'-1234.56'>;
|
|
648
|
+
//=> -1234.56
|
|
431
649
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
// @ts-expect-error
|
|
435
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
436
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
437
|
-
```
|
|
650
|
+
type PositiveInfinity = StringToNumber<'Infinity'>;
|
|
651
|
+
//=> Infinity
|
|
438
652
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
*/
|
|
443
|
-
type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
|
|
444
|
-
//#endregion
|
|
445
|
-
//#region ../../node_modules/.pnpm/type-fest@5.10.0/node_modules/type-fest/source/is-equal.d.ts
|
|
446
|
-
/**
|
|
447
|
-
Returns a boolean for whether the two given types are equal.
|
|
448
|
-
|
|
449
|
-
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
450
|
-
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
653
|
+
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
654
|
+
//=> -Infinity
|
|
655
|
+
```
|
|
451
656
|
|
|
452
|
-
|
|
453
|
-
- 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.
|
|
454
658
|
|
|
455
659
|
@example
|
|
456
660
|
```
|
|
457
|
-
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
|
|
458
668
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
? true
|
|
465
|
-
: Includes<rest, Item>
|
|
466
|
-
: false;
|
|
669
|
+
type NumericSeparators = StringToNumber<'12_345'>;
|
|
670
|
+
//=> never
|
|
671
|
+
|
|
672
|
+
type TooLarge = StringToNumber<'9007199254740993'>;
|
|
673
|
+
//=> never
|
|
467
674
|
```
|
|
468
675
|
|
|
469
|
-
@
|
|
470
|
-
|
|
676
|
+
@see {@link StringToBoolean} - For parsing a boolean string.
|
|
677
|
+
|
|
678
|
+
@category String
|
|
679
|
+
@category Numeric
|
|
680
|
+
@category Template literal
|
|
471
681
|
*/
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
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;
|
|
475
685
|
//#endregion
|
|
476
|
-
//#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
|
|
477
687
|
/**
|
|
478
688
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
479
689
|
|
|
@@ -484,34 +694,34 @@ Use-cases:
|
|
|
484
694
|
|
|
485
695
|
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
486
696
|
|
|
487
|
-
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>`.
|
|
488
698
|
|
|
489
|
-
|
|
699
|
+
The `never` value type prevents inherited `Object.prototype` members, such as `toString`, from satisfying an explicitly defined key.
|
|
490
700
|
|
|
491
701
|
```
|
|
492
|
-
const indexed: Record<string,
|
|
702
|
+
const indexed: Record<string, never> = {}; // Allowed
|
|
493
703
|
|
|
494
704
|
// @ts-expect-error
|
|
495
|
-
const keyed: Record<'foo',
|
|
496
|
-
// 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
|
|
497
707
|
```
|
|
498
708
|
|
|
499
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:
|
|
500
710
|
|
|
501
711
|
```
|
|
502
|
-
type Indexed = {} extends Record<string,
|
|
503
|
-
? '✅ `{}` is assignable to `Record<string,
|
|
504
|
-
: '❌ `{}` 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>`';
|
|
505
715
|
|
|
506
716
|
type IndexedResult = Indexed;
|
|
507
|
-
//=> '✅ `{}` is assignable to `Record<string,
|
|
717
|
+
//=> '✅ `{}` is assignable to `Record<string, never>`'
|
|
508
718
|
|
|
509
|
-
type Keyed = {} extends Record<'foo' | 'bar',
|
|
510
|
-
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\',
|
|
511
|
-
: '❌ `{}` 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>`';
|
|
512
722
|
|
|
513
723
|
type KeyedResult = Keyed;
|
|
514
|
-
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\',
|
|
724
|
+
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', never>`'
|
|
515
725
|
```
|
|
516
726
|
|
|
517
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`...
|
|
@@ -523,15 +733,15 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
523
733
|
};
|
|
524
734
|
```
|
|
525
735
|
|
|
526
|
-
...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>`)...
|
|
527
737
|
|
|
528
738
|
```
|
|
529
739
|
type OmitIndexSignature<ObjectType> = {
|
|
530
740
|
[KeyType in keyof ObjectType
|
|
531
|
-
// Is `{}` assignable to `Record<KeyType,
|
|
532
|
-
as {} extends Record<KeyType,
|
|
533
|
-
? never // ✅ `{}` is assignable to `Record<KeyType,
|
|
534
|
-
: 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>`
|
|
535
745
|
]: ObjectType[KeyType];
|
|
536
746
|
};
|
|
537
747
|
```
|
|
@@ -565,9 +775,9 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
565
775
|
@see {@link PickIndexSignature}
|
|
566
776
|
@category Object
|
|
567
777
|
*/
|
|
568
|
-
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]; };
|
|
569
779
|
//#endregion
|
|
570
|
-
//#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
|
|
571
781
|
/**
|
|
572
782
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
573
783
|
|
|
@@ -613,137 +823,261 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
613
823
|
@see {@link OmitIndexSignature}
|
|
614
824
|
@category Object
|
|
615
825
|
*/
|
|
616
|
-
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]; };
|
|
617
827
|
//#endregion
|
|
618
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
619
|
-
// Merges two objects without worrying about index signatures.
|
|
620
|
-
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key]; } & Source>;
|
|
828
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/internal/keys.d.ts
|
|
621
829
|
/**
|
|
622
|
-
|
|
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]; };
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/internal/object.d.ts
|
|
835
|
+
/**
|
|
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.
|
|
623
837
|
|
|
624
|
-
|
|
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.
|
|
625
843
|
|
|
626
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'
|
|
627
857
|
```
|
|
628
|
-
|
|
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.
|
|
629
862
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
863
|
+
@example
|
|
864
|
+
```ts
|
|
865
|
+
enum Color {
|
|
866
|
+
Red = 'red',
|
|
867
|
+
}
|
|
634
868
|
|
|
635
|
-
type
|
|
636
|
-
|
|
637
|
-
|
|
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;
|
|
638
894
|
};
|
|
639
895
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
//=> never
|
|
896
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
897
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
643
898
|
|
|
644
|
-
//
|
|
645
|
-
|
|
646
|
-
|
|
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"'.
|
|
647
902
|
```
|
|
648
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
|
+
|
|
649
929
|
@example
|
|
650
930
|
```
|
|
651
|
-
import type {
|
|
931
|
+
import type {ApplyDefaultOptions} from 'type-fest';
|
|
652
932
|
|
|
653
|
-
type
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
foo: string;
|
|
657
|
-
bar: symbol;
|
|
933
|
+
type FormatOptions = {
|
|
934
|
+
uppercase?: boolean;
|
|
935
|
+
prefix?: string;
|
|
658
936
|
};
|
|
659
937
|
|
|
660
|
-
type
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
bar: Date;
|
|
664
|
-
baz: boolean;
|
|
938
|
+
type DefaultFormatOptions = {
|
|
939
|
+
uppercase: false;
|
|
940
|
+
prefix: '';
|
|
665
941
|
};
|
|
666
942
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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: ''}
|
|
676
955
|
```
|
|
677
956
|
|
|
678
|
-
|
|
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.
|
|
679
963
|
|
|
680
|
-
@see {@link
|
|
964
|
+
@see {@link DefaultsFor}
|
|
681
965
|
@category Object
|
|
682
966
|
*/
|
|
683
|
-
type
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
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]; }>>>;
|
|
688
975
|
//#endregion
|
|
689
|
-
//#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
|
|
690
977
|
/**
|
|
691
|
-
|
|
978
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
692
979
|
|
|
693
980
|
@example
|
|
694
981
|
```
|
|
695
|
-
|
|
696
|
-
type
|
|
697
|
-
|
|
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'
|
|
698
989
|
|
|
699
|
-
|
|
700
|
-
|
|
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'
|
|
701
993
|
```
|
|
702
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
|
+
|
|
703
997
|
@example
|
|
704
|
-
```
|
|
705
|
-
|
|
998
|
+
```ts
|
|
999
|
+
import type {StringRepeat} from 'type-fest';
|
|
706
1000
|
|
|
707
|
-
type
|
|
708
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
709
|
-
type SpecifiedOptions = {};
|
|
1001
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
710
1002
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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.
|
|
1011
|
+
|
|
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
|
+
//=> ''
|
|
714
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`.
|
|
715
1042
|
|
|
716
1043
|
@example
|
|
717
1044
|
```
|
|
718
|
-
|
|
1045
|
+
import type {RequireNone} from 'type-fest';
|
|
1046
|
+
|
|
1047
|
+
type DeprecatedOptions = RequireNone<'legacyMode' | 'callback'>;
|
|
1048
|
+
//=> {legacyMode?: never; callback?: never}
|
|
719
1049
|
|
|
720
|
-
type
|
|
721
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
722
|
-
type SpecifiedOptions = {};
|
|
1050
|
+
type Options = {url: string} & DeprecatedOptions;
|
|
723
1051
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
//
|
|
1052
|
+
const options: Options = {url: 'https://example.com'};
|
|
1053
|
+
|
|
1054
|
+
// @ts-expect-error
|
|
1055
|
+
const deprecated: Options = {url: 'https://example.com', legacyMode: true};
|
|
727
1056
|
```
|
|
728
1057
|
|
|
729
1058
|
@example
|
|
730
1059
|
```
|
|
731
|
-
|
|
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;
|
|
732
1064
|
|
|
733
|
-
|
|
734
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
735
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1065
|
+
insert({name: 'Alice'});
|
|
736
1066
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1067
|
+
// @ts-expect-error
|
|
1068
|
+
insert({id: 1, name: 'Alice'});
|
|
740
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
|
|
741
1077
|
*/
|
|
742
|
-
type
|
|
743
|
-
) ? Result : never;
|
|
744
|
-
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; };
|
|
745
1079
|
//#endregion
|
|
746
|
-
//#region ../../node_modules/.pnpm/type-fest@
|
|
1080
|
+
//#region ../../node_modules/.pnpm/type-fest@6.0.3/node_modules/type-fest/source/except.d.ts
|
|
747
1081
|
/**
|
|
748
1082
|
Filter out keys from an object.
|
|
749
1083
|
|
|
@@ -771,7 +1105,7 @@ type Filtered = Filter<'bar', 'foo'>;
|
|
|
771
1105
|
|
|
772
1106
|
@see {Except}
|
|
773
1107
|
*/
|
|
774
|
-
type Filter<KeyType, ExcludeType> =
|
|
1108
|
+
type Filter<KeyType, ExcludeType> = Exclude<KeyType, ExcludeType>;
|
|
775
1109
|
type ExceptOptions = {
|
|
776
1110
|
/**
|
|
777
1111
|
Disallow assigning non-specified properties.
|
|
@@ -794,6 +1128,8 @@ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/
|
|
|
794
1128
|
|
|
795
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)).
|
|
796
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
|
+
|
|
797
1133
|
@example
|
|
798
1134
|
```
|
|
799
1135
|
import type {Except} from 'type-fest';
|
|
@@ -811,7 +1147,7 @@ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
|
811
1147
|
// errors: 'a' does not exist in type '{ b: string; }'
|
|
812
1148
|
|
|
813
1149
|
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
814
|
-
//=> {a: number} &
|
|
1150
|
+
//=> {a: number} & {b?: never}
|
|
815
1151
|
|
|
816
1152
|
// @ts-expect-error
|
|
817
1153
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
@@ -840,13 +1176,20 @@ type PostPayloadFixed = Except<UserData, 'email'>;
|
|
|
840
1176
|
|
|
841
1177
|
@category Object
|
|
842
1178
|
*/
|
|
843
|
-
type Except<ObjectType, KeysType extends
|
|
844
|
-
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]; };
|
|
845
1182
|
//#endregion
|
|
846
|
-
//#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
|
|
847
1184
|
/**
|
|
848
1185
|
Create a type that requires at least one of the given keys, while keeping the remaining keys as is.
|
|
849
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
|
+
|
|
850
1193
|
@example
|
|
851
1194
|
```
|
|
852
1195
|
import type {RequireAtLeastOne} from 'type-fest';
|
|
@@ -865,14 +1208,18 @@ const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
|
865
1208
|
|
|
866
1209
|
@category Object
|
|
867
1210
|
*/
|
|
868
|
-
type RequireAtLeastOne<ObjectType, KeysType extends
|
|
869
|
-
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>>>;
|
|
870
1213
|
}>;
|
|
871
|
-
|
|
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> = { [
|
|
872
1219
|
// For each `Key` in `KeysType` make a mapped type:
|
|
873
|
-
Key in KeysType]-?:
|
|
874
|
-
&
|
|
875
|
-
|
|
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`
|
|
876
1223
|
//#endregion
|
|
877
1224
|
//#region src-js/plugins/tokens.d.ts
|
|
878
1225
|
/**
|
|
@@ -1004,7 +1351,7 @@ interface ObjectProperty extends Span {
|
|
|
1004
1351
|
optional?: false;
|
|
1005
1352
|
parent: Node$1;
|
|
1006
1353
|
}
|
|
1007
|
-
type PropertyKey$1 = IdentifierName | PrivateIdentifier | Expression;
|
|
1354
|
+
type PropertyKey$1 = IdentifierName | StringLiteral | NumericLiteral | BigIntLiteral | PrivateIdentifier | Expression;
|
|
1008
1355
|
type PropertyKind = "init" | "get" | "set";
|
|
1009
1356
|
interface TemplateLiteral extends Span {
|
|
1010
1357
|
type: "TemplateLiteral";
|
|
@@ -3362,4 +3709,4 @@ interface DecisionPlugin {
|
|
|
3362
3709
|
declare const defineDecisionRule: <const Rule extends DecisionRule>(rule: Rule) => Rule;
|
|
3363
3710
|
declare const createDecisionPlugin: (setup: DecisionPluginSetup) => DecisionPlugin;
|
|
3364
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 };
|
|
3365
|
-
//# sourceMappingURL=index-
|
|
3712
|
+
//# sourceMappingURL=index-CK88FBE5.d.mts.map
|