@augment-vir/core 32.2.0 → 32.2.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/dist/augments/type/apply-default-options.d.ts +24 -0
- package/dist/augments/type/apply-default-options.js +1 -0
- package/dist/augments/type/conditional-type.d.ts +13 -1
- package/dist/augments/type/except.d.ts +8 -5
- package/dist/augments/type/exclude-exactly.d.ts +27 -0
- package/dist/augments/type/exclude-exactly.js +1 -0
- package/dist/augments/type/merge.d.ts +20 -0
- package/dist/augments/type/merge.js +1 -0
- package/dist/augments/type/omit-deep.d.ts +94 -11
- package/dist/augments/type/omit-index-signature.d.ts +14 -0
- package/dist/augments/type/package-json.d.ts +1 -0
- package/dist/augments/type/partial-deep.d.ts +13 -13
- package/dist/augments/type/require-keys.d.ts +20 -16
- package/dist/augments/type/require-one-or-none.d.ts +6 -4
- package/dist/augments/type/type-checks.d.ts +9 -8
- package/dist/augments/type/type-checks.js +5 -6
- package/dist/augments/type/union-member.d.ts +14 -0
- package/dist/augments/type/union-member.js +1 -0
- package/dist/augments/type/union-to-tuple.d.ts +11 -8
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RequiredKeysOf } from '../object/required-keys.js';
|
|
2
|
+
import { type If } from './conditional-type.js';
|
|
3
|
+
import { type Merge } from './merge.js';
|
|
4
|
+
import { type OptionalKeysOf } from './optional-keys-of.js';
|
|
5
|
+
import { type Simplify } from './simplify.js';
|
|
6
|
+
import { type IsAny, type IsNever } from './type-checks.js';
|
|
7
|
+
/**
|
|
8
|
+
* Fill in the unspecified properties of an options object with their defaults.
|
|
9
|
+
*
|
|
10
|
+
* Copied from the `ApplyDefaultOptions` type in the `type-fest` package so that this package's
|
|
11
|
+
* public types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
12
|
+
*
|
|
13
|
+
* @category Object
|
|
14
|
+
* @category Package : @augment-vir/common
|
|
15
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
+
*/
|
|
17
|
+
export type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, {
|
|
18
|
+
[Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key];
|
|
19
|
+
}> &
|
|
20
|
+
/**
|
|
21
|
+
* `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is
|
|
22
|
+
* always assignable to `Required<SomeOption>`.
|
|
23
|
+
*/
|
|
24
|
+
Required<Options>>>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IsNever } from './type-checks.js';
|
|
1
|
+
import { type IsAny, type IsNever } from './type-checks.js';
|
|
2
2
|
/**
|
|
3
3
|
* An if-else-like type that resolves depending on whether the given `boolean` type is `true` or
|
|
4
4
|
* `false`. Returns the else branch when the given type is `never`.
|
|
@@ -11,3 +11,15 @@ import { type IsNever } from './type-checks.js';
|
|
|
11
11
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
12
|
*/
|
|
13
13
|
export type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves to `IfNotAnyOrNeverBranch` unless the given type is `any` or `never`, in which case the
|
|
16
|
+
* respective `IfAny` or `IfNever` branch is used.
|
|
17
|
+
*
|
|
18
|
+
* Copied from the `IfNotAnyOrNever` type in the `type-fest` package so that this package's public
|
|
19
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
20
|
+
*
|
|
21
|
+
* @category Type
|
|
22
|
+
* @category Package : @augment-vir/common
|
|
23
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
24
|
+
*/
|
|
25
|
+
export type IfNotAnyOrNever<Type, IfNotAnyOrNeverBranch, IfAny = any, IfNever = never> = If<IsAny<Type>, IfAny, If<IsNever<Type>, IfNever, IfNotAnyOrNeverBranch>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ApplyDefaultOptions } from './apply-default-options.js';
|
|
1
2
|
import { type IsEqual } from './type-checks.js';
|
|
2
3
|
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : KeyType extends ExcludeType ? never : KeyType;
|
|
3
4
|
/**
|
|
@@ -18,6 +19,12 @@ export type ExceptOptions = {
|
|
|
18
19
|
*/
|
|
19
20
|
requireExactProps?: boolean;
|
|
20
21
|
};
|
|
22
|
+
type DefaultExceptOptions = {
|
|
23
|
+
requireExactProps: false;
|
|
24
|
+
};
|
|
25
|
+
type ExceptHelper<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
|
|
26
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
27
|
+
} & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
|
|
21
28
|
/**
|
|
22
29
|
* Create a type from an object type without certain keys. This is a stricter version of the
|
|
23
30
|
* built-in `Omit` type: it restricts the omitted keys to keys present on the given type.
|
|
@@ -29,9 +36,5 @@ export type ExceptOptions = {
|
|
|
29
36
|
* @category Package : @augment-vir/common
|
|
30
37
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
31
38
|
*/
|
|
32
|
-
export type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
|
|
33
|
-
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
34
|
-
} & (Options extends {
|
|
35
|
-
requireExactProps: true;
|
|
36
|
-
} ? Partial<Record<KeysType, never>> : {});
|
|
39
|
+
export type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = ExceptHelper<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
37
40
|
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type If, type IfNotAnyOrNever } from './conditional-type.js';
|
|
2
|
+
import { type IsAny, type IsEqual, type IsNever } from './type-checks.js';
|
|
3
|
+
type ExcludeExactlyMember<Union, Delete> = IfNotAnyOrNever<Delete, Union extends unknown ? [
|
|
4
|
+
Delete extends unknown ? If<IsEqual<Union, Delete>, true, never> : never
|
|
5
|
+
] extends [never] ? Union : never : never,
|
|
6
|
+
/**
|
|
7
|
+
* When `Delete` is `any` or `never`, return `Union`, because `Union` cannot be `any` or `never`
|
|
8
|
+
* here.
|
|
9
|
+
*/
|
|
10
|
+
Union, Union>;
|
|
11
|
+
/**
|
|
12
|
+
* Exclude exactly the given type from a union, instead of excluding every member assignable to it
|
|
13
|
+
* the way the built-in `Exclude` does.
|
|
14
|
+
*
|
|
15
|
+
* Copied from the `ExcludeExactly` type in the `type-fest` package so that this package's public
|
|
16
|
+
* types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
17
|
+
*
|
|
18
|
+
* @category Type
|
|
19
|
+
* @category Package : @augment-vir/common
|
|
20
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
21
|
+
*/
|
|
22
|
+
export type ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Union, ExcludeExactlyMember<Union, Delete>,
|
|
23
|
+
/** When `Union` is `any`: if `Delete` is `any` return `never`, otherwise return `Union`. */
|
|
24
|
+
If<IsAny<Delete>, never, Union>,
|
|
25
|
+
/** When `Union` is `never`: if `Delete` is `never` return `never`, otherwise return `Union`. */
|
|
26
|
+
If<IsNever<Delete>, never, Union>>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type If } from './conditional-type.js';
|
|
2
|
+
import { type OmitIndexSignature, type PickIndexSignature } from './omit-index-signature.js';
|
|
3
|
+
import { type Simplify } from './simplify.js';
|
|
4
|
+
import { type IsEqual } from './type-checks.js';
|
|
5
|
+
type SimpleMerge<Destination, Source> = Simplify<{
|
|
6
|
+
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
7
|
+
} & Source>;
|
|
8
|
+
type MergeNonEqual<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
9
|
+
/**
|
|
10
|
+
* Merge two types into a new type. Keys of the second type override keys of the first type.
|
|
11
|
+
*
|
|
12
|
+
* Copied from the `Merge` type in the `type-fest` package so that this package's public types do
|
|
13
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
14
|
+
*
|
|
15
|
+
* @category Object
|
|
16
|
+
* @category Package : @augment-vir/common
|
|
17
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
18
|
+
*/
|
|
19
|
+
export type Merge<Destination, Source> = Destination extends unknown ? Source extends unknown ? If<IsEqual<Destination, Source>, Destination, MergeNonEqual<Destination, Source>> : never : never;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ApplyDefaultOptions } from './apply-default-options.js';
|
|
1
2
|
import { type BuiltIns } from './built-in-type.js';
|
|
2
3
|
import { type If } from './conditional-type.js';
|
|
3
4
|
import { type LiteralUnion } from './literal-union.js';
|
|
@@ -34,9 +35,9 @@ type PositiveNumericStringGt<A extends string, B extends string> = A extends B ?
|
|
|
34
35
|
...infer Remaining extends readonly unknown[]
|
|
35
36
|
] ? 0 extends Remaining['length'] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
|
|
36
37
|
/**
|
|
37
|
-
* Simplified 2-input logical `and`. `type-fest` routes `And` through `AndAll`/`AllExtend`, but
|
|
38
|
-
*
|
|
39
|
-
* definition is behaviorally identical.
|
|
38
|
+
* Simplified 2-input logical `and`. `type-fest` routes `And` through `AndAll`/`AllExtend`, but
|
|
39
|
+
* every consumer here (`GreaterThan` and `InternalPaths`) always passes concrete `true`/`false`
|
|
40
|
+
* values, for which this definition is behaviorally identical.
|
|
40
41
|
*/
|
|
41
42
|
type And<A extends boolean, B extends boolean> = A extends true ? B extends true ? true : false : false;
|
|
42
43
|
/** Simplified 2-input logical `or`. See the note on {@link And}. */
|
|
@@ -174,6 +175,29 @@ type SubtractPostChecks<A extends number, B extends number, AreNegative = [
|
|
|
174
175
|
...TupleOf<Absolute<B>>
|
|
175
176
|
] extends infer R extends unknown[] ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length'] : never;
|
|
176
177
|
type Subtract<A extends number, B extends number> = number extends A | B ? number : A extends B & (PositiveInfinity | NegativeInfinity) ? number : A extends NegativeInfinity ? NegativeInfinity : B extends PositiveInfinity ? NegativeInfinity : A extends PositiveInfinity ? PositiveInfinity : B extends NegativeInfinity ? PositiveInfinity : A extends B ? 0 : A extends 0 ? ReverseSign<B> : B extends 0 ? A : SubtractPostChecks<A, B>;
|
|
178
|
+
type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [
|
|
179
|
+
infer First extends number,
|
|
180
|
+
...infer Rest extends number[]
|
|
181
|
+
] ? GreaterThan<First, Result> extends true ? TupleMax<Rest, First> : TupleMax<Rest, Result> : Result;
|
|
182
|
+
type SumPositives<A extends number, B extends number> = [
|
|
183
|
+
...TupleOf<A>,
|
|
184
|
+
...TupleOf<B>
|
|
185
|
+
]['length'] extends infer Result extends number ? Result : never;
|
|
186
|
+
type SumPostChecks<A extends number, B extends number, AreNegative = [
|
|
187
|
+
IsNegative<A>,
|
|
188
|
+
IsNegative<B>
|
|
189
|
+
]> = AreNegative extends [
|
|
190
|
+
false,
|
|
191
|
+
false
|
|
192
|
+
] ? SumPositives<A, B> : AreNegative extends [
|
|
193
|
+
true,
|
|
194
|
+
true
|
|
195
|
+
] ? ReverseSign<SumPositives<Absolute<A>, Absolute<B>>> : Absolute<Subtract<Absolute<A>, Absolute<B>>> extends infer Result extends number ? TupleMax<[
|
|
196
|
+
Absolute<A>,
|
|
197
|
+
Absolute<B>
|
|
198
|
+
]> extends infer LargestMagnitude extends number ? LargestMagnitude extends A | B ? Result : ReverseSign<Result> : never : never;
|
|
199
|
+
type Sum<A extends number, B extends number> = number extends A | B ? number : A extends B & (PositiveInfinity | NegativeInfinity) ? A : A | B extends PositiveInfinity | NegativeInfinity ? number : A extends PositiveInfinity | NegativeInfinity ? A : B extends PositiveInfinity | NegativeInfinity ? B : A extends 0 ? B : B extends 0 ? A : A extends ReverseSign<B> ? 0 : SumPostChecks<A, B>;
|
|
200
|
+
type IsNumberLike<N> = IfNotAnyOrNever<N, N extends number | `${number}` ? true : false, boolean, false>;
|
|
177
201
|
type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = []> = T extends unknown ? number extends T['length'] ? T extends readonly [
|
|
178
202
|
infer U,
|
|
179
203
|
...infer V
|
|
@@ -259,6 +283,70 @@ type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> =
|
|
|
259
283
|
[TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType>;
|
|
260
284
|
} : Type;
|
|
261
285
|
type SimplifyDeep<Type, ExcludeType = never> = ConditionalSimplifyDeep<Type, ExcludeType | NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray>, object>;
|
|
286
|
+
/**
|
|
287
|
+
* Options for {@link Paths}.
|
|
288
|
+
*
|
|
289
|
+
* Copied from the `PathsOptions` type in `type-fest` v5.6 so that this package's public types do
|
|
290
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
291
|
+
*
|
|
292
|
+
* @category Object
|
|
293
|
+
* @category Package : @augment-vir/common
|
|
294
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
295
|
+
*/
|
|
296
|
+
export type PathsOptions = {
|
|
297
|
+
/**
|
|
298
|
+
* The maximum depth to recurse when searching for paths. Range: 0 ~ 10.
|
|
299
|
+
*
|
|
300
|
+
* @default 5
|
|
301
|
+
*/
|
|
302
|
+
maxRecursionDepth?: number;
|
|
303
|
+
/**
|
|
304
|
+
* Use bracket notation for array indices and numeric object keys.
|
|
305
|
+
*
|
|
306
|
+
* @default false
|
|
307
|
+
*/
|
|
308
|
+
bracketNotation?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Only include leaf paths in the output.
|
|
311
|
+
*
|
|
312
|
+
* @default false
|
|
313
|
+
*/
|
|
314
|
+
leavesOnly?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Only include paths at the specified depth. By default all paths up to
|
|
317
|
+
* {@link PathsOptions.maxRecursionDepth} are included. Depth starts at `0` for root properties.
|
|
318
|
+
*
|
|
319
|
+
* @default number
|
|
320
|
+
*/
|
|
321
|
+
depth?: number;
|
|
322
|
+
};
|
|
323
|
+
type DefaultPathsOptions = {
|
|
324
|
+
maxRecursionDepth: 5;
|
|
325
|
+
bracketNotation: false;
|
|
326
|
+
leavesOnly: false;
|
|
327
|
+
depth: number;
|
|
328
|
+
};
|
|
329
|
+
type InternalPaths<T, Options extends Required<PathsOptions>, CurrentDepth extends number> = {
|
|
330
|
+
[Key in keyof T]: Key extends string | number ? (And<Options['bracketNotation'], IsNumberLike<Key>> extends true ? `[${Key}]` : CurrentDepth extends 0 ? /**
|
|
331
|
+
* Return both `Key` and `ToString<Key>` because for number keys, like `1`, both `1` and `'1'` are
|
|
332
|
+
* valid keys.
|
|
333
|
+
*/ Key | ToString<Key> : `.${Key | ToString<Key>}`) extends infer TransformedKey extends string | number ? ((Options['leavesOnly'] extends true ? Options['maxRecursionDepth'] extends CurrentDepth ? TransformedKey : IsNever<T[Key]> extends true ? TransformedKey : T[Key] extends infer Value ? Value extends readonly [] | NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray> ? TransformedKey : IsNever<keyof Value> extends true ? TransformedKey : never : never : TransformedKey) extends infer LeafFilteredKey ? CurrentDepth extends Options['depth'] ? LeafFilteredKey : never : never)
|
|
334
|
+
/** Recursively generate paths for the current key. */
|
|
335
|
+
| (GreaterThan<Options['maxRecursionDepth'], CurrentDepth> extends true ? `${TransformedKey}${PathsHelper<T[Key], Options, Sum<CurrentDepth, 1>> & (string | number)}` : never) : never : never;
|
|
336
|
+
}[keyof T & (T extends UnknownArray ? number : unknown)];
|
|
337
|
+
type PathsHelper<T, Options extends Required<PathsOptions>, CurrentDepth extends number = 0> = T extends NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray> ? never : IsAny<T> extends true ? never : T extends object ? InternalPaths<Required<T>, Options, CurrentDepth> : never;
|
|
338
|
+
/**
|
|
339
|
+
* Generate a union of all possible paths to properties in the given object. Also works with arrays.
|
|
340
|
+
*
|
|
341
|
+
* Copied from the `Paths` type in `type-fest` v5.6 so that this package's public types do not
|
|
342
|
+
* depend on `type-fest` (see the note in `type-checks.ts`).
|
|
343
|
+
*
|
|
344
|
+
* @category Object
|
|
345
|
+
* @category Array
|
|
346
|
+
* @category Package : @augment-vir/common
|
|
347
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
348
|
+
*/
|
|
349
|
+
export type Paths<T, Options extends PathsOptions = {}> = PathsHelper<T, ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, Options>>;
|
|
262
350
|
type OmitDeepArrayWithOnePath<ArrayType extends UnknownArray, P extends string | number> = P extends `${infer ArrayIndex extends number}.${infer SubPath}` ? number extends ArrayIndex ? Array<OmitDeepWithOnePath<NonNullable<ArrayType[number]>, SubPath>> : ArraySplice<ArrayType, ArrayIndex, 1, [
|
|
263
351
|
OmitDeepWithOnePath<NonNullable<ArrayType[ArrayIndex]>, SubPath>
|
|
264
352
|
]> : P extends `${infer ArrayIndex extends number}` ? number extends ArrayIndex ? [] : ArraySplice<ArrayType, ArrayIndex, 1, [unknown]> : ArrayType;
|
|
@@ -274,17 +362,12 @@ type OmitDeepHelper<T, PathTuple extends UnknownArray> = PathTuple extends [
|
|
|
274
362
|
* Omit properties from a deeply-nested object, supporting recursion into arrays (each removed array
|
|
275
363
|
* item is replaced with `unknown` at its index).
|
|
276
364
|
*
|
|
277
|
-
* Copied from the `OmitDeep` type in
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
* Note: `type-fest` constrains `PathUnion` to `LiteralUnion<Paths<T>, string>`. That `Paths<T>`
|
|
281
|
-
* portion is only an autocomplete/validation aid on the path argument and is not used by the
|
|
282
|
-
* omission logic, so it is relaxed here to `LiteralUnion<string, string>` (effectively `string`) to
|
|
283
|
-
* avoid vendoring type-fest's enormous `Paths` type.
|
|
365
|
+
* Copied from the `OmitDeep` type in `type-fest` v5.6 so that this package's public types do not
|
|
366
|
+
* depend on `type-fest` (see the note in `type-checks.ts`).
|
|
284
367
|
*
|
|
285
368
|
* @category Object
|
|
286
369
|
* @category Package : @augment-vir/common
|
|
287
370
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
288
371
|
*/
|
|
289
|
-
export type OmitDeep<T, PathUnion extends LiteralUnion<
|
|
372
|
+
export type OmitDeep<T, PathUnion extends LiteralUnion<Paths<T>, string>> = SimplifyDeep<OmitDeepHelper<T, UnionToTuple<PathUnion>>, UnknownArray>;
|
|
290
373
|
export {};
|
|
@@ -12,3 +12,17 @@
|
|
|
12
12
|
export type OmitIndexSignature<ObjectType> = {
|
|
13
13
|
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType];
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Pick only index signatures from the given object type, leaving out all explicitly defined
|
|
17
|
+
* properties. This is the counterpart of {@link OmitIndexSignature}.
|
|
18
|
+
*
|
|
19
|
+
* Copied from the `PickIndexSignature` type in the `type-fest` package so that this package's
|
|
20
|
+
* public types do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
21
|
+
*
|
|
22
|
+
* @category Object
|
|
23
|
+
* @category Package : @augment-vir/common
|
|
24
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
25
|
+
*/
|
|
26
|
+
export type PickIndexSignature<ObjectType> = {
|
|
27
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType];
|
|
28
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ApplyDefaultOptions } from './apply-default-options.js';
|
|
1
2
|
import { type BuiltIns, type HasMultipleCallSignatures } from './built-in-type.js';
|
|
2
3
|
import { type IsNever } from './type-checks.js';
|
|
3
4
|
/**
|
|
@@ -24,12 +25,16 @@ export type PartialDeepOptions = {
|
|
|
24
25
|
*/
|
|
25
26
|
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
26
27
|
};
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type
|
|
32
|
-
|
|
28
|
+
type DefaultPartialDeepOptions = {
|
|
29
|
+
recurseIntoArrays: false;
|
|
30
|
+
allowUndefinedInNonTupleArrays: false;
|
|
31
|
+
};
|
|
32
|
+
type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<PartialDeepHelper<KeyType, Options>, PartialDeepHelper<ValueType, Options>>;
|
|
33
|
+
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<PartialDeepHelper<T, Options>>;
|
|
34
|
+
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<PartialDeepHelper<KeyType, Options>, PartialDeepHelper<ValueType, Options>>;
|
|
35
|
+
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<PartialDeepHelper<T, Options>>;
|
|
36
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
|
|
37
|
+
[KeyType in keyof ObjectType]?: PartialDeepHelper<ObjectType[KeyType], Options>;
|
|
33
38
|
};
|
|
34
39
|
/**
|
|
35
40
|
* Create a deeply optional version of another type. Use `Partial<T>` if you only need one level
|
|
@@ -42,11 +47,6 @@ type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOpt
|
|
|
42
47
|
* @category Package : @augment-vir/common
|
|
43
48
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
44
49
|
*/
|
|
45
|
-
export type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
46
|
-
|
|
47
|
-
} ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<PartialDeep<Options extends {
|
|
48
|
-
allowUndefinedInNonTupleArrays: true;
|
|
49
|
-
} ? ItemType | undefined : ItemType, Options>> : Array<PartialDeep<Options extends {
|
|
50
|
-
allowUndefinedInNonTupleArrays: true;
|
|
51
|
-
} ? ItemType | undefined : ItemType, Options>> : PartialObjectDeep<T, Options> : T : PartialObjectDeep<T, Options> : unknown;
|
|
50
|
+
export type PartialDeep<T, Options extends PartialDeepOptions = {}> = PartialDeepHelper<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
51
|
+
type PartialDeepHelper<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends (...arguments_: any[]) => unknown ? IsNever<keyof T> extends true ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep<T, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> ? Options['recurseIntoArrays'] extends true ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<PartialDeepHelper<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<PartialDeepHelper<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep<T, Options> : T : PartialObjectDeep<T, Options> : unknown;
|
|
52
52
|
export {};
|
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
import { type RequiredKeysOf } from '../object/required-keys.js';
|
|
2
|
+
import { type If, type IfNotAnyOrNever } from './conditional-type.js';
|
|
3
|
+
import { type Except } from './except.js';
|
|
4
|
+
import { type IsAny, type IsNever } from './type-checks.js';
|
|
2
5
|
/**
|
|
3
6
|
* Returns `true` if the given object type has at least one required key, otherwise `false`.
|
|
4
7
|
*
|
|
5
|
-
* Copied from the `HasRequiredKeys` type in
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* Copied from the `HasRequiredKeys` type in `type-fest` v5.6 (built on {@link RequiredKeysOf}) so
|
|
9
|
+
* that this package's public types do not depend on `type-fest` (see the note in
|
|
10
|
+
* `type-checks.ts`).
|
|
8
11
|
*
|
|
9
12
|
* @category Object
|
|
10
13
|
* @category Package : @augment-vir/common
|
|
11
14
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
15
|
*/
|
|
13
|
-
export type HasRequiredKeys<BaseType> =
|
|
16
|
+
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
17
|
+
type RequireExactlyOneHelper<ObjectType, KeysType extends keyof ObjectType> = {
|
|
18
|
+
[Key in KeysType]: Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>;
|
|
19
|
+
}[KeysType] & Omit<ObjectType, KeysType>;
|
|
14
20
|
/**
|
|
15
21
|
* Create a type that requires exactly one of the given keys and disallows the rest, while keeping
|
|
16
22
|
* the remaining (non-listed) keys as is.
|
|
17
23
|
*
|
|
18
|
-
* Copied from the
|
|
19
|
-
* `type-fest`
|
|
20
|
-
* assignability). See the note in `type-checks.ts`.
|
|
24
|
+
* Copied from the `RequireExactlyOne` type in `type-fest` v5.6 so that this package's public types
|
|
25
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
21
26
|
*
|
|
22
27
|
* @category Object
|
|
23
28
|
* @category Package : @augment-vir/common
|
|
24
29
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
25
30
|
*/
|
|
26
|
-
export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever<KeysType>, never, RequireExactlyOneHelper<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
32
|
+
type RequireAtLeastOneHelper<ObjectType, KeysType extends keyof ObjectType> = {
|
|
33
|
+
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & Partial<Pick<ObjectType, Exclude<KeysType, Key>>>;
|
|
34
|
+
}[KeysType] & Except<ObjectType, KeysType>;
|
|
29
35
|
/**
|
|
30
36
|
* Create a type that requires at least one of the given keys, while keeping the remaining
|
|
31
37
|
* (non-listed) keys as is.
|
|
32
38
|
*
|
|
33
|
-
* Copied from the
|
|
34
|
-
* `type-fest`
|
|
35
|
-
* `type-checks.ts`.
|
|
39
|
+
* Copied from the `RequireAtLeastOne` type in `type-fest` v5.6 so that this package's public types
|
|
40
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
36
41
|
*
|
|
37
42
|
* @category Object
|
|
38
43
|
* @category Package : @augment-vir/common
|
|
39
44
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
40
45
|
*/
|
|
41
|
-
export type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
|
|
42
|
-
|
|
43
|
-
}[KeysType] & Omit<ObjectType, KeysType>;
|
|
46
|
+
export type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever<KeysType>, never, RequireAtLeastOneHelper<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
47
|
+
export {};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import { type If, type IfNotAnyOrNever } from './conditional-type.js';
|
|
1
2
|
import { type RequireExactlyOne } from './require-keys.js';
|
|
3
|
+
import { type IsAny, type IsNever } from './type-checks.js';
|
|
2
4
|
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
5
|
+
type RequireOneOrNoneHelper<ObjectType, KeysType extends keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>;
|
|
3
6
|
/**
|
|
4
7
|
* Create a type that requires exactly one of the given keys or none of the given keys, while
|
|
5
8
|
* keeping the remaining keys as is.
|
|
6
9
|
*
|
|
7
|
-
* Copied from the
|
|
8
|
-
* `type-fest`
|
|
9
|
-
* `type-checks.ts`.
|
|
10
|
+
* Copied from the `RequireOneOrNone` type in `type-fest` v5.6 so that this package's public types
|
|
11
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
10
12
|
*
|
|
11
13
|
* @category Object
|
|
12
14
|
* @category Package : @augment-vir/common
|
|
13
15
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
14
16
|
*/
|
|
15
|
-
export type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
|
|
17
|
+
export type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever<KeysType>, ObjectType, RequireOneOrNoneHelper<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
16
18
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* These type predicates are copied from
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* consumers. These local copies use only built-in types so they never reference `type-fest`.
|
|
2
|
+
* These type predicates are copied from `type-fest` v5.6 rather than imported from it. Owning them
|
|
3
|
+
* here keeps `@augment-vir` (and its consumers) decoupled from `type-fest`'s evolving internals:
|
|
4
|
+
* these utilities leak through the public `.d.ts` of downstream packages, so a `type-fest` upgrade
|
|
5
|
+
* could otherwise silently break consumers. These local copies use only built-in types so they
|
|
6
|
+
* never reference `type-fest`.
|
|
8
7
|
*/
|
|
8
|
+
type IsEqualHelper<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
|
|
9
9
|
/**
|
|
10
10
|
* Returns `true` if the two given types are exactly equal, otherwise `false`.
|
|
11
11
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @category Package : @augment-vir/common
|
|
14
14
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
15
15
|
*/
|
|
16
|
-
export type IsEqual<A, B> =
|
|
16
|
+
export type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? IsEqualHelper<A, B> : false : false;
|
|
17
17
|
/**
|
|
18
18
|
* Returns `true` if the given type is `never`, otherwise `false`.
|
|
19
19
|
*
|
|
@@ -29,4 +29,5 @@ export type IsNever<T> = [T] extends [never] ? true : false;
|
|
|
29
29
|
* @category Package : @augment-vir/common
|
|
30
30
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
31
31
|
*/
|
|
32
|
-
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
32
|
+
export type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
33
|
+
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* These type predicates are copied from
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* consumers. These local copies use only built-in types so they never reference `type-fest`.
|
|
2
|
+
* These type predicates are copied from `type-fest` v5.6 rather than imported from it. Owning them
|
|
3
|
+
* here keeps `@augment-vir` (and its consumers) decoupled from `type-fest`'s evolving internals:
|
|
4
|
+
* these utilities leak through the public `.d.ts` of downstream packages, so a `type-fest` upgrade
|
|
5
|
+
* could otherwise silently break consumers. These local copies use only built-in types so they
|
|
6
|
+
* never reference `type-fest`.
|
|
8
7
|
*/
|
|
9
8
|
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type IsNever } from './type-checks.js';
|
|
2
|
+
import { type UnionToIntersection } from './union-to-intersection.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a single member of the given union. Which member is returned is not guaranteed, but it is
|
|
5
|
+
* deterministic for a given union.
|
|
6
|
+
*
|
|
7
|
+
* Copied from the `UnionMember` type in the `type-fest` package so that this package's public types
|
|
8
|
+
* do not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
9
|
+
*
|
|
10
|
+
* @category Type
|
|
11
|
+
* @category Package : @augment-vir/common
|
|
12
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
13
|
+
*/
|
|
14
|
+
export type UnionMember<T> = IsNever<T> extends true ? never : UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { type ExcludeExactly } from './exclude-exactly.js';
|
|
2
|
+
import { type IsNever } from './type-checks.js';
|
|
3
|
+
import { type UnionMember } from './union-member.js';
|
|
4
|
+
import { type UnknownArray } from './unknown-array.js';
|
|
5
|
+
type UnionToTupleHelper<Union, Accumulator extends UnknownArray = [], Member = UnionMember<Union>> = IsNever<Union> extends true ? Accumulator : UnionToTupleHelper<ExcludeExactly<Union, Member>, [
|
|
6
|
+
Member,
|
|
7
|
+
...Accumulator
|
|
8
|
+
]>;
|
|
3
9
|
/**
|
|
4
10
|
* Convert a union type into an unordered tuple type of its elements. The order of the resulting
|
|
5
11
|
* tuple is not guaranteed.
|
|
6
12
|
*
|
|
7
|
-
* Copied from the `UnionToTuple` type in
|
|
8
|
-
*
|
|
13
|
+
* Copied from the `UnionToTuple` type in `type-fest` v5.6 so that this package's public types do
|
|
14
|
+
* not depend on `type-fest` (see the note in `type-checks.ts`).
|
|
9
15
|
*
|
|
10
16
|
* @category Array
|
|
11
17
|
* @category Package : @augment-vir/common
|
|
12
18
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
13
19
|
*/
|
|
14
|
-
export type UnionToTuple<Union
|
|
15
|
-
LastOfUnion<Union>,
|
|
16
|
-
...Accumulator
|
|
17
|
-
]>;
|
|
20
|
+
export type UnionToTuple<Union> = UnionToTupleHelper<Union> extends infer Result extends UnknownArray ? Result : never;
|
|
18
21
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from './augments/string/match.js';
|
|
|
39
39
|
export * from './augments/string/punctuation.js';
|
|
40
40
|
export * from './augments/string/remove-duplicate-characters.js';
|
|
41
41
|
export * from './augments/string/uuid.js';
|
|
42
|
+
export * from './augments/type/apply-default-options.js';
|
|
42
43
|
export * from './augments/type/branded-type.js';
|
|
43
44
|
export * from './augments/type/built-in-type.js';
|
|
44
45
|
export * from './augments/type/conditional-type.js';
|
|
@@ -47,9 +48,11 @@ export * from './augments/type/distributed-omit.js';
|
|
|
47
48
|
export * from './augments/type/empty-object.js';
|
|
48
49
|
export * from './augments/type/exact.js';
|
|
49
50
|
export * from './augments/type/except.js';
|
|
51
|
+
export * from './augments/type/exclude-exactly.js';
|
|
50
52
|
export * from './augments/type/is-unknown.js';
|
|
51
53
|
export * from './augments/type/keys-of-union.js';
|
|
52
54
|
export * from './augments/type/literal-union.js';
|
|
55
|
+
export * from './augments/type/merge.js';
|
|
53
56
|
export * from './augments/type/non-empty-string.js';
|
|
54
57
|
export * from './augments/type/omit-deep.js';
|
|
55
58
|
export * from './augments/type/omit-index-signature.js';
|
|
@@ -70,6 +73,7 @@ export * from './augments/type/tagged.js';
|
|
|
70
73
|
export * from './augments/type/type-checks.js';
|
|
71
74
|
export * from './augments/type/typed-array.js';
|
|
72
75
|
export * from './augments/type/undefined-to-optional.js';
|
|
76
|
+
export * from './augments/type/union-member.js';
|
|
73
77
|
export * from './augments/type/union-to-intersection.js';
|
|
74
78
|
export * from './augments/type/union-to-tuple.js';
|
|
75
79
|
export * from './augments/type/unknown-array.js';
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ export * from './augments/string/match.js';
|
|
|
39
39
|
export * from './augments/string/punctuation.js';
|
|
40
40
|
export * from './augments/string/remove-duplicate-characters.js';
|
|
41
41
|
export * from './augments/string/uuid.js';
|
|
42
|
+
export * from './augments/type/apply-default-options.js';
|
|
42
43
|
export * from './augments/type/branded-type.js';
|
|
43
44
|
export * from './augments/type/built-in-type.js';
|
|
44
45
|
export * from './augments/type/conditional-type.js';
|
|
@@ -47,9 +48,11 @@ export * from './augments/type/distributed-omit.js';
|
|
|
47
48
|
export * from './augments/type/empty-object.js';
|
|
48
49
|
export * from './augments/type/exact.js';
|
|
49
50
|
export * from './augments/type/except.js';
|
|
51
|
+
export * from './augments/type/exclude-exactly.js';
|
|
50
52
|
export * from './augments/type/is-unknown.js';
|
|
51
53
|
export * from './augments/type/keys-of-union.js';
|
|
52
54
|
export * from './augments/type/literal-union.js';
|
|
55
|
+
export * from './augments/type/merge.js';
|
|
53
56
|
export * from './augments/type/non-empty-string.js';
|
|
54
57
|
export * from './augments/type/omit-deep.js';
|
|
55
58
|
export * from './augments/type/omit-index-signature.js';
|
|
@@ -70,6 +73,7 @@ export * from './augments/type/tagged.js';
|
|
|
70
73
|
export * from './augments/type/type-checks.js';
|
|
71
74
|
export * from './augments/type/typed-array.js';
|
|
72
75
|
export * from './augments/type/undefined-to-optional.js';
|
|
76
|
+
export * from './augments/type/union-member.js';
|
|
73
77
|
export * from './augments/type/union-to-intersection.js';
|
|
74
78
|
export * from './augments/type/union-to-tuple.js';
|
|
75
79
|
export * from './augments/type/unknown-array.js';
|