Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
178
node_modules/type-fest/index.d.ts
generated
vendored
Normal file
178
node_modules/type-fest/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
// Basic
|
||||
export * from './source/primitive';
|
||||
export * from './source/typed-array';
|
||||
export * from './source/basic';
|
||||
export * from './source/observable-like';
|
||||
|
||||
// Utilities
|
||||
export type {KeysOfUnion} from './source/keys-of-union';
|
||||
export type {DistributedOmit} from './source/distributed-omit';
|
||||
export type {DistributedPick} from './source/distributed-pick';
|
||||
export type {EmptyObject, IsEmptyObject} from './source/empty-object';
|
||||
export type {IfEmptyObject} from './source/if-empty-object';
|
||||
export type {NonEmptyObject} from './source/non-empty-object';
|
||||
export type {NonEmptyString} from './source/non-empty-string';
|
||||
export type {UnknownRecord} from './source/unknown-record';
|
||||
export type {UnknownArray} from './source/unknown-array';
|
||||
export type {UnknownSet} from './source/unknown-set';
|
||||
export type {UnknownMap} from './source/unknown-map';
|
||||
export type {Except} from './source/except';
|
||||
export type {TaggedUnion} from './source/tagged-union';
|
||||
export type {Writable} from './source/writable';
|
||||
export type {WritableDeep} from './source/writable-deep';
|
||||
export type {Merge} from './source/merge';
|
||||
export type {MergeDeep, MergeDeepOptions} from './source/merge-deep';
|
||||
export type {MergeExclusive} from './source/merge-exclusive';
|
||||
export type {RequireAtLeastOne} from './source/require-at-least-one';
|
||||
export type {RequireExactlyOne} from './source/require-exactly-one';
|
||||
export type {RequireAllOrNone} from './source/require-all-or-none';
|
||||
export type {RequireOneOrNone} from './source/require-one-or-none';
|
||||
export type {SingleKeyObject} from './source/single-key-object';
|
||||
export type {OmitIndexSignature} from './source/omit-index-signature';
|
||||
export type {PickIndexSignature} from './source/pick-index-signature';
|
||||
export type {PartialDeep, PartialDeepOptions} from './source/partial-deep';
|
||||
export type {RequiredDeep} from './source/required-deep';
|
||||
export type {PickDeep} from './source/pick-deep';
|
||||
export type {OmitDeep} from './source/omit-deep';
|
||||
export type {PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions} from './source/partial-on-undefined-deep';
|
||||
export type {UndefinedOnPartialDeep} from './source/undefined-on-partial-deep';
|
||||
export type {ReadonlyDeep} from './source/readonly-deep';
|
||||
export type {LiteralUnion} from './source/literal-union';
|
||||
export type {Promisable} from './source/promisable';
|
||||
export type {Arrayable} from './source/arrayable';
|
||||
export type {Opaque, UnwrapOpaque, Tagged, GetTagMetadata, UnwrapTagged} from './source/tagged';
|
||||
export type {InvariantOf} from './source/invariant-of';
|
||||
export type {SetOptional} from './source/set-optional';
|
||||
export type {SetReadonly} from './source/set-readonly';
|
||||
export type {SetRequired} from './source/set-required';
|
||||
export type {SetRequiredDeep} from './source/set-required-deep';
|
||||
export type {SetNonNullable} from './source/set-non-nullable';
|
||||
export type {SetNonNullableDeep} from './source/set-non-nullable-deep';
|
||||
export type {ValueOf} from './source/value-of';
|
||||
export type {AsyncReturnType} from './source/async-return-type';
|
||||
export type {ConditionalExcept} from './source/conditional-except';
|
||||
export type {ConditionalKeys} from './source/conditional-keys';
|
||||
export type {ConditionalPick} from './source/conditional-pick';
|
||||
export type {ConditionalPickDeep, ConditionalPickDeepOptions} from './source/conditional-pick-deep';
|
||||
export type {UnionToIntersection} from './source/union-to-intersection';
|
||||
export type {Stringified} from './source/stringified';
|
||||
export type {StringSlice} from './source/string-slice';
|
||||
export type {FixedLengthArray} from './source/fixed-length-array';
|
||||
export type {MultidimensionalArray} from './source/multidimensional-array';
|
||||
export type {MultidimensionalReadonlyArray} from './source/multidimensional-readonly-array';
|
||||
export type {IterableElement} from './source/iterable-element';
|
||||
export type {Entry} from './source/entry';
|
||||
export type {Entries} from './source/entries';
|
||||
export type {SetReturnType} from './source/set-return-type';
|
||||
export type {SetParameterType} from './source/set-parameter-type';
|
||||
export type {Asyncify} from './source/asyncify';
|
||||
export type {Simplify} from './source/simplify';
|
||||
export type {SimplifyDeep} from './source/simplify-deep';
|
||||
export type {Jsonify} from './source/jsonify';
|
||||
export type {Jsonifiable} from './source/jsonifiable';
|
||||
export type {StructuredCloneable} from './source/structured-cloneable';
|
||||
export type {Schema, SchemaOptions} from './source/schema';
|
||||
export type {LiteralToPrimitive} from './source/literal-to-primitive';
|
||||
export type {LiteralToPrimitiveDeep} from './source/literal-to-primitive-deep';
|
||||
export type {
|
||||
PositiveInfinity,
|
||||
NegativeInfinity,
|
||||
Finite,
|
||||
Integer,
|
||||
Float,
|
||||
NegativeFloat,
|
||||
Negative,
|
||||
NonNegative,
|
||||
NegativeInteger,
|
||||
NonNegativeInteger,
|
||||
IsNegative,
|
||||
} from './source/numeric';
|
||||
export type {GreaterThan} from './source/greater-than';
|
||||
export type {GreaterThanOrEqual} from './source/greater-than-or-equal';
|
||||
export type {LessThan} from './source/less-than';
|
||||
export type {LessThanOrEqual} from './source/less-than-or-equal';
|
||||
export type {Sum} from './source/sum';
|
||||
export type {Subtract} from './source/subtract';
|
||||
export type {StringKeyOf} from './source/string-key-of';
|
||||
export type {Exact} from './source/exact';
|
||||
export type {ReadonlyTuple} from './source/readonly-tuple';
|
||||
export type {OptionalKeysOf} from './source/optional-keys-of';
|
||||
export type {OverrideProperties} from './source/override-properties';
|
||||
export type {HasOptionalKeys} from './source/has-optional-keys';
|
||||
export type {RequiredKeysOf} from './source/required-keys-of';
|
||||
export type {HasRequiredKeys} from './source/has-required-keys';
|
||||
export type {ReadonlyKeysOf} from './source/readonly-keys-of';
|
||||
export type {HasReadonlyKeys} from './source/has-readonly-keys';
|
||||
export type {WritableKeysOf} from './source/writable-keys-of';
|
||||
export type {HasWritableKeys} from './source/has-writable-keys';
|
||||
export type {Spread} from './source/spread';
|
||||
export type {IsInteger} from './source/is-integer';
|
||||
export type {IsFloat} from './source/is-float';
|
||||
export type {TupleToObject} from './source/tuple-to-object';
|
||||
export type {TupleToUnion} from './source/tuple-to-union';
|
||||
export type {UnionToTuple} from './source/union-to-tuple';
|
||||
export type {IntRange} from './source/int-range';
|
||||
export type {IntClosedRange} from './source/int-closed-range';
|
||||
export type {IsEqual} from './source/is-equal';
|
||||
export type {
|
||||
IsLiteral,
|
||||
IsStringLiteral,
|
||||
IsNumericLiteral,
|
||||
IsBooleanLiteral,
|
||||
IsSymbolLiteral,
|
||||
} from './source/is-literal';
|
||||
export type {IsAny} from './source/is-any';
|
||||
export type {IfAny} from './source/if-any';
|
||||
export type {IsNever} from './source/is-never';
|
||||
export type {IfNever} from './source/if-never';
|
||||
export type {IsUnknown} from './source/is-unknown';
|
||||
export type {IfUnknown} from './source/if-unknown';
|
||||
export type {IsTuple} from './source/is-tuple';
|
||||
export type {ArrayIndices} from './source/array-indices';
|
||||
export type {ArrayValues} from './source/array-values';
|
||||
export type {ArraySlice} from './source/array-slice';
|
||||
export type {ArraySplice} from './source/array-splice';
|
||||
export type {ArrayTail} from './source/array-tail';
|
||||
export type {SetFieldType} from './source/set-field-type';
|
||||
export type {Paths} from './source/paths';
|
||||
export type {AllUnionFields} from './source/all-union-fields';
|
||||
export type {SharedUnionFields} from './source/shared-union-fields';
|
||||
export type {SharedUnionFieldsDeep} from './source/shared-union-fields-deep';
|
||||
export type {IsNull} from './source/is-null';
|
||||
export type {IfNull} from './source/if-null';
|
||||
export type {And} from './source/and';
|
||||
export type {Or} from './source/or';
|
||||
export type {NonEmptyTuple} from './source/non-empty-tuple';
|
||||
export type {FindGlobalInstanceType, FindGlobalType} from './source/find-global-type';
|
||||
|
||||
// Template literal types
|
||||
export type {CamelCase} from './source/camel-case';
|
||||
export type {CamelCasedProperties} from './source/camel-cased-properties';
|
||||
export type {CamelCasedPropertiesDeep} from './source/camel-cased-properties-deep';
|
||||
export type {KebabCase} from './source/kebab-case';
|
||||
export type {KebabCasedProperties} from './source/kebab-cased-properties';
|
||||
export type {KebabCasedPropertiesDeep} from './source/kebab-cased-properties-deep';
|
||||
export type {PascalCase} from './source/pascal-case';
|
||||
export type {PascalCasedProperties} from './source/pascal-cased-properties';
|
||||
export type {PascalCasedPropertiesDeep} from './source/pascal-cased-properties-deep';
|
||||
export type {SnakeCase} from './source/snake-case';
|
||||
export type {SnakeCasedProperties} from './source/snake-cased-properties';
|
||||
export type {SnakeCasedPropertiesDeep} from './source/snake-cased-properties-deep';
|
||||
export type {ScreamingSnakeCase} from './source/screaming-snake-case';
|
||||
export type {DelimiterCase} from './source/delimiter-case';
|
||||
export type {DelimiterCasedProperties} from './source/delimiter-cased-properties';
|
||||
export type {DelimiterCasedPropertiesDeep} from './source/delimiter-cased-properties-deep';
|
||||
export type {Join} from './source/join';
|
||||
export type {Split} from './source/split';
|
||||
export type {Words} from './source/words';
|
||||
export type {Trim} from './source/trim';
|
||||
export type {Replace} from './source/replace';
|
||||
export type {StringRepeat} from './source/string-repeat';
|
||||
export type {Includes} from './source/includes';
|
||||
export type {Get} from './source/get';
|
||||
export type {LastArrayElement} from './source/last-array-element';
|
||||
|
||||
// Miscellaneous
|
||||
export type {GlobalThis} from './source/global-this';
|
||||
export type {PackageJson} from './source/package-json';
|
||||
export type {TsConfigJson} from './source/tsconfig-json';
|
121
node_modules/type-fest/license-cc0
generated
vendored
Normal file
121
node_modules/type-fest/license-cc0
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
9
node_modules/type-fest/license-mit
generated
vendored
Normal file
9
node_modules/type-fest/license-mit
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
91
node_modules/type-fest/package.json
generated
vendored
Normal file
91
node_modules/type-fest/package.json
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "type-fest",
|
||||
"version": "4.41.0",
|
||||
"description": "A collection of essential TypeScript types",
|
||||
"license": "(MIT OR CC0-1.0)",
|
||||
"repository": "sindresorhus/type-fest",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"scripts": {
|
||||
"test:source-files-extension": "node script/test/source-files-extension.js",
|
||||
"test:tsc": "tsc",
|
||||
"test:tsd": "tsd",
|
||||
"test:xo": "xo",
|
||||
"test": "run-p test:*"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"source",
|
||||
"license-mit",
|
||||
"license-cc0"
|
||||
],
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"ts",
|
||||
"types",
|
||||
"utility",
|
||||
"util",
|
||||
"utilities",
|
||||
"omit",
|
||||
"merge",
|
||||
"json",
|
||||
"generics"
|
||||
],
|
||||
"devDependencies": {
|
||||
"expect-type": "^1.1.0",
|
||||
"npm-run-all2": "^7.0.1",
|
||||
"tsd": "^0.32.0",
|
||||
"typescript": "~5.8.3",
|
||||
"xo": "^0.60.0"
|
||||
},
|
||||
"xo": {
|
||||
"rules": {
|
||||
"@typescript-eslint/no-extraneous-class": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-types": "off",
|
||||
"@typescript-eslint/naming-convention": "off",
|
||||
"import/extensions": "off",
|
||||
"@typescript-eslint/no-redeclare": "off",
|
||||
"@typescript-eslint/no-confusing-void-expression": "off",
|
||||
"@typescript-eslint/no-unsafe-argument": "off",
|
||||
"n/file-extension-in-import": "off",
|
||||
"object-curly-newline": [
|
||||
"error",
|
||||
{
|
||||
"multiline": true,
|
||||
"consistent": true
|
||||
}
|
||||
],
|
||||
"import/consistent-type-specifier-style": [
|
||||
"error",
|
||||
"prefer-top-level"
|
||||
]
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": "**/*.d.ts",
|
||||
"rules": {
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
"tsd",
|
||||
"expect-type"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tsd": {
|
||||
"compilerOptions": {
|
||||
"noUnusedLocals": false
|
||||
}
|
||||
}
|
||||
}
|
1060
node_modules/type-fest/readme.md
generated
vendored
Normal file
1060
node_modules/type-fest/readme.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
88
node_modules/type-fest/source/all-union-fields.d.ts
generated
vendored
Normal file
88
node_modules/type-fest/source/all-union-fields.d.ts
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import type {NonRecursiveType, ReadonlyKeysOfUnion, ValueOfUnion} from './internal';
|
||||
import type {KeysOfUnion} from './keys-of-union';
|
||||
import type {SharedUnionFields} from './shared-union-fields';
|
||||
import type {Simplify} from './simplify';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
/**
|
||||
Create a type with all fields from a union of object types.
|
||||
|
||||
Use-cases:
|
||||
- You want a safe object type where each key exists in the union object.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {AllUnionFields} from 'type-fest';
|
||||
|
||||
type Cat = {
|
||||
name: string;
|
||||
type: 'cat';
|
||||
catType: string;
|
||||
};
|
||||
|
||||
type Dog = {
|
||||
name: string;
|
||||
type: 'dog';
|
||||
dogType: string;
|
||||
};
|
||||
|
||||
function displayPetInfo(petInfo: Cat | Dog) {
|
||||
// typeof petInfo =>
|
||||
// {
|
||||
// name: string;
|
||||
// type: 'cat';
|
||||
// catType: string;
|
||||
// } | {
|
||||
// name: string;
|
||||
// type: 'dog';
|
||||
// dogType: string;
|
||||
// }
|
||||
|
||||
console.log('name: ', petInfo.name);
|
||||
console.log('type: ', petInfo.type);
|
||||
|
||||
// TypeScript complains about `catType` and `dogType` not existing on type `Cat | Dog`.
|
||||
console.log('animal type: ', petInfo.catType ?? petInfo.dogType);
|
||||
}
|
||||
|
||||
function displayPetInfo(petInfo: AllUnionFields<Cat | Dog>) {
|
||||
// typeof petInfo =>
|
||||
// {
|
||||
// name: string;
|
||||
// type: 'cat' | 'dog';
|
||||
// catType?: string;
|
||||
// dogType?: string;
|
||||
// }
|
||||
|
||||
console.log('name: ', petInfo.name);
|
||||
console.log('type: ', petInfo.type);
|
||||
|
||||
// No TypeScript error.
|
||||
console.log('animal type: ', petInfo.catType ?? petInfo.dogType);
|
||||
}
|
||||
```
|
||||
|
||||
@see SharedUnionFields
|
||||
|
||||
@category Object
|
||||
@category Union
|
||||
*/
|
||||
export type AllUnionFields<Union> =
|
||||
Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
|
||||
? Exclude<Union, SkippedMembers> extends infer RelevantMembers
|
||||
?
|
||||
| SkippedMembers
|
||||
| Simplify<
|
||||
// Include fields that are common in all union members
|
||||
SharedUnionFields<RelevantMembers> &
|
||||
// Include readonly fields present in any union member
|
||||
{
|
||||
readonly [P in ReadonlyKeysOfUnion<RelevantMembers>]?: ValueOfUnion<RelevantMembers, P & KeysOfUnion<RelevantMembers>>
|
||||
} &
|
||||
// Include remaining fields that are neither common nor readonly
|
||||
{
|
||||
[P in Exclude<KeysOfUnion<RelevantMembers>, ReadonlyKeysOfUnion<RelevantMembers> | keyof RelevantMembers>]?: ValueOfUnion<RelevantMembers, P>
|
||||
}
|
||||
>
|
||||
: never
|
||||
: never;
|
25
node_modules/type-fest/source/and.d.ts
generated
vendored
Normal file
25
node_modules/type-fest/source/and.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import type {IsEqual} from './is-equal';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether two given types are both true.
|
||||
|
||||
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {And} from 'type-fest';
|
||||
|
||||
And<true, true>;
|
||||
//=> true
|
||||
|
||||
And<true, false>;
|
||||
//=> false
|
||||
```
|
||||
|
||||
@see {@link Or}
|
||||
*/
|
||||
export type And<A extends boolean, B extends boolean> = [A, B][number] extends true
|
||||
? true
|
||||
: true extends [IsEqual<A, false>, IsEqual<B, false>][number]
|
||||
? false
|
||||
: never;
|
23
node_modules/type-fest/source/array-indices.d.ts
generated
vendored
Normal file
23
node_modules/type-fest/source/array-indices.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
Provides valid indices for a constant array or tuple.
|
||||
|
||||
Use-case: This type is useful when working with constant arrays or tuples and you want to enforce type-safety for accessing elements by their indices.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ArrayIndices, ArrayValues} from 'type-fest';
|
||||
|
||||
const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as const;
|
||||
|
||||
type Weekday = ArrayIndices<typeof weekdays>;
|
||||
type WeekdayName = ArrayValues<typeof weekdays>;
|
||||
|
||||
const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
|
||||
```
|
||||
|
||||
@see {@link ArrayValues}
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type ArrayIndices<Element extends readonly unknown[]> =
|
||||
Exclude<Partial<Element>['length'], Element['length']>;
|
109
node_modules/type-fest/source/array-slice.d.ts
generated
vendored
Normal file
109
node_modules/type-fest/source/array-slice.d.ts
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
import type {Sum} from './sum';
|
||||
import type {LessThanOrEqual} from './less-than-or-equal';
|
||||
import type {GreaterThanOrEqual} from './greater-than-or-equal';
|
||||
import type {GreaterThan} from './greater-than';
|
||||
import type {IsNegative} from './numeric';
|
||||
import type {Not, TupleMin} from './internal';
|
||||
import type {IsEqual} from './is-equal';
|
||||
import type {And} from './and';
|
||||
import type {ArraySplice} from './array-splice';
|
||||
|
||||
/**
|
||||
Returns an array slice of a given range, just like `Array#slice()`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ArraySlice} from 'type-fest';
|
||||
|
||||
type T0 = ArraySlice<[0, 1, 2, 3, 4]>;
|
||||
//=> [0, 1, 2, 3, 4]
|
||||
|
||||
type T1 = ArraySlice<[0, 1, 2, 3, 4], 0, -1>;
|
||||
//=> [0, 1, 2, 3]
|
||||
|
||||
type T2 = ArraySlice<[0, 1, 2, 3, 4], 1, -2>;
|
||||
//=> [1, 2]
|
||||
|
||||
type T3 = ArraySlice<[0, 1, 2, 3, 4], -2, 4>;
|
||||
//=> [3]
|
||||
|
||||
type T4 = ArraySlice<[0, 1, 2, 3, 4], -2, -1>;
|
||||
//=> [3]
|
||||
|
||||
type T5 = ArraySlice<[0, 1, 2, 3, 4], 0, -999>;
|
||||
//=> []
|
||||
|
||||
function arraySlice<
|
||||
const Array_ extends readonly unknown[],
|
||||
Start extends number = 0,
|
||||
End extends number = Array_['length'],
|
||||
>(array: Array_, start?: Start, end?: End) {
|
||||
return array.slice(start, end) as ArraySlice<Array_, Start, End>;
|
||||
}
|
||||
|
||||
const slice = arraySlice([1, '2', {a: 3}, [4, 5]], 0, -1);
|
||||
|
||||
typeof slice;
|
||||
//=> [1, '2', { readonly a: 3; }]
|
||||
|
||||
slice[2].a;
|
||||
//=> 3
|
||||
|
||||
// @ts-expect-error -- TS2493: Tuple type '[1, "2", {readonly a: 3}]' of length '3' has no element at index '3'.
|
||||
slice[3];
|
||||
```
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type ArraySlice<
|
||||
Array_ extends readonly unknown[],
|
||||
Start extends number = never,
|
||||
End extends number = never,
|
||||
> = Array_ extends unknown // To distributive type
|
||||
? And<IsEqual<Start, never>, IsEqual<End, never>> extends true
|
||||
? Array_
|
||||
: number extends Array_['length']
|
||||
? VariableLengthArraySliceHelper<Array_, Start, End>
|
||||
: ArraySliceHelper<Array_, IsEqual<Start, never> extends true ? 0 : Start, IsEqual<End, never> extends true ? Array_['length'] : End>
|
||||
: never; // Never happens
|
||||
|
||||
type VariableLengthArraySliceHelper<
|
||||
Array_ extends readonly unknown[],
|
||||
Start extends number,
|
||||
End extends number,
|
||||
> = And<Not<IsNegative<Start>>, IsEqual<End, never>> extends true
|
||||
? ArraySplice<Array_, 0, Start>
|
||||
: And<
|
||||
And<Not<IsNegative<Start>>, Not<IsNegative<End>>>,
|
||||
IsEqual<GreaterThan<End, Start>, true>
|
||||
> extends true
|
||||
? ArraySliceByPositiveIndex<Array_, Start, End>
|
||||
: [];
|
||||
|
||||
type ArraySliceHelper<
|
||||
Array_ extends readonly unknown[],
|
||||
Start extends number = 0,
|
||||
End extends number = Array_['length'],
|
||||
TraversedElement extends Array<Array_[number]> = [],
|
||||
Result extends Array<Array_[number]> = [],
|
||||
ArrayLength extends number = Array_['length'],
|
||||
PositiveS extends number = IsNegative<Start> extends true
|
||||
? Sum<ArrayLength, Start> extends infer AddResult extends number
|
||||
? number extends AddResult // (ArrayLength + Start) < 0
|
||||
? 0
|
||||
: GreaterThan<AddResult, 0> extends true ? AddResult : 0
|
||||
: never
|
||||
: Start,
|
||||
PositiveE extends number = IsNegative<End> extends true ? Sum<ArrayLength, End> : End,
|
||||
> = true extends [IsNegative<PositiveS>, LessThanOrEqual<PositiveE, PositiveS>, GreaterThanOrEqual<PositiveS, ArrayLength>][number]
|
||||
? []
|
||||
: ArraySliceByPositiveIndex<Array_, TupleMin<[PositiveS, ArrayLength]>, TupleMin<[PositiveE, ArrayLength]>>;
|
||||
|
||||
type ArraySliceByPositiveIndex<
|
||||
Array_ extends readonly unknown[],
|
||||
Start extends number,
|
||||
End extends number,
|
||||
Result extends Array<Array_[number]> = [],
|
||||
> = Start extends End
|
||||
? Result
|
||||
: ArraySliceByPositiveIndex<Array_, Sum<Start, 1>, End, [...Result, Array_[Start]]>;
|
99
node_modules/type-fest/source/array-splice.d.ts
generated
vendored
Normal file
99
node_modules/type-fest/source/array-splice.d.ts
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
import type {BuildTuple, StaticPartOfArray, VariablePartOfArray} from './internal';
|
||||
import type {GreaterThanOrEqual} from './greater-than-or-equal';
|
||||
import type {Subtract} from './subtract';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
/**
|
||||
The implementation of `SplitArrayByIndex` for fixed length arrays.
|
||||
*/
|
||||
type SplitFixedArrayByIndex<T extends UnknownArray, SplitIndex extends number> =
|
||||
SplitIndex extends 0
|
||||
? [[], T]
|
||||
: T extends readonly [...BuildTuple<SplitIndex>, ...infer V]
|
||||
? T extends readonly [...infer U, ...V]
|
||||
? [U, V]
|
||||
: [never, never]
|
||||
: [never, never];
|
||||
|
||||
/**
|
||||
The implementation of `SplitArrayByIndex` for variable length arrays.
|
||||
*/
|
||||
type SplitVariableArrayByIndex<T extends UnknownArray,
|
||||
SplitIndex extends number,
|
||||
T1 = Subtract<SplitIndex, StaticPartOfArray<T>['length']>,
|
||||
T2 = T1 extends number
|
||||
? BuildTuple<GreaterThanOrEqual<T1, 0> extends true ? T1 : number, VariablePartOfArray<T>[number]>
|
||||
: [],
|
||||
> =
|
||||
SplitIndex extends 0
|
||||
? [[], T]
|
||||
: GreaterThanOrEqual<StaticPartOfArray<T>['length'], SplitIndex> extends true
|
||||
? [
|
||||
SplitFixedArrayByIndex<StaticPartOfArray<T>, SplitIndex>[0],
|
||||
[
|
||||
...SplitFixedArrayByIndex<StaticPartOfArray<T>, SplitIndex>[1],
|
||||
...VariablePartOfArray<T>,
|
||||
],
|
||||
]
|
||||
: [
|
||||
[
|
||||
...StaticPartOfArray<T>,
|
||||
...(T2 extends UnknownArray ? T2 : []),
|
||||
],
|
||||
VariablePartOfArray<T>,
|
||||
];
|
||||
|
||||
/**
|
||||
Split the given array `T` by the given `SplitIndex`.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = SplitArrayByIndex<[1, 2, 3, 4], 2>;
|
||||
// type A = [[1, 2], [3, 4]];
|
||||
|
||||
type B = SplitArrayByIndex<[1, 2, 3, 4], 0>;
|
||||
// type B = [[], [1, 2, 3, 4]];
|
||||
```
|
||||
*/
|
||||
type SplitArrayByIndex<T extends UnknownArray, SplitIndex extends number> =
|
||||
SplitIndex extends 0
|
||||
? [[], T]
|
||||
: number extends T['length']
|
||||
? SplitVariableArrayByIndex<T, SplitIndex>
|
||||
: SplitFixedArrayByIndex<T, SplitIndex>;
|
||||
|
||||
/**
|
||||
Creates a new array type by adding or removing elements at a specified index range in the original array.
|
||||
|
||||
Use-case: Replace or insert items in an array type.
|
||||
|
||||
Like [`Array#splice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) but for types.
|
||||
|
||||
@example
|
||||
```
|
||||
type SomeMonths0 = ['January', 'April', 'June'];
|
||||
type Mouths0 = ArraySplice<SomeMonths0, 1, 0, ['Feb', 'March']>;
|
||||
//=> type Mouths0 = ['January', 'Feb', 'March', 'April', 'June'];
|
||||
|
||||
type SomeMonths1 = ['January', 'April', 'June'];
|
||||
type Mouths1 = ArraySplice<SomeMonths1, 1, 1>;
|
||||
//=> type Mouths1 = ['January', 'June'];
|
||||
|
||||
type SomeMonths2 = ['January', 'Foo', 'April'];
|
||||
type Mouths2 = ArraySplice<SomeMonths2, 1, 1, ['Feb', 'March']>;
|
||||
//=> type Mouths2 = ['January', 'Feb', 'March', 'April'];
|
||||
```
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type ArraySplice<
|
||||
T extends UnknownArray,
|
||||
Start extends number,
|
||||
DeleteCount extends number,
|
||||
Items extends UnknownArray = [],
|
||||
> =
|
||||
SplitArrayByIndex<T, Start> extends [infer U extends UnknownArray, infer V extends UnknownArray]
|
||||
? SplitArrayByIndex<V, DeleteCount> extends [infer _Deleted extends UnknownArray, infer X extends UnknownArray]
|
||||
? [...U, ...Items, ...X]
|
||||
: never // Should never happen
|
||||
: never; // Should never happen
|
76
node_modules/type-fest/source/array-tail.d.ts
generated
vendored
Normal file
76
node_modules/type-fest/source/array-tail.d.ts
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import type {ApplyDefaultOptions, IfArrayReadonly} from './internal';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
/**
|
||||
@see {@link ArrayTail}
|
||||
*/
|
||||
type ArrayTailOptions = {
|
||||
/**
|
||||
Return a readonly array if the input array is readonly.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ArrayTail} from 'type-fest';
|
||||
|
||||
type Example1 = ArrayTail<readonly [string, number, boolean], {preserveReadonly: true}>;
|
||||
//=> readonly [number, boolean]
|
||||
|
||||
type Example2 = ArrayTail<[string, number, boolean], {preserveReadonly: true}>;
|
||||
//=> [number, boolean]
|
||||
|
||||
type Example3 = ArrayTail<readonly [string, number, boolean], {preserveReadonly: false}>;
|
||||
//=> [number, boolean]
|
||||
|
||||
type Example4 = ArrayTail<[string, number, boolean], {preserveReadonly: false}>;
|
||||
//=> [number, boolean]
|
||||
```
|
||||
*/
|
||||
preserveReadonly?: boolean;
|
||||
};
|
||||
|
||||
type DefaultArrayTailOptions = {
|
||||
preserveReadonly: false;
|
||||
};
|
||||
|
||||
/**
|
||||
Extracts the type of an array or tuple minus the first element.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ArrayTail} from 'type-fest';
|
||||
|
||||
declare const curry: <Arguments extends unknown[], Return>(
|
||||
function_: (...arguments_: Arguments) => Return,
|
||||
...arguments_: ArrayTail<Arguments>
|
||||
) => (...arguments_: ArrayTail<Arguments>) => Return;
|
||||
|
||||
const add = (a: number, b: number) => a + b;
|
||||
|
||||
const add3 = curry(add, 3);
|
||||
|
||||
add3(4);
|
||||
//=> 7
|
||||
```
|
||||
|
||||
@see {@link ArrayTailOptions}
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type ArrayTail<TArray extends UnknownArray, Options extends ArrayTailOptions = {}> =
|
||||
ApplyDefaultOptions<ArrayTailOptions, DefaultArrayTailOptions, Options> extends infer ResolvedOptions extends Required<ArrayTailOptions>
|
||||
? TArray extends UnknownArray // For distributing `TArray`
|
||||
? _ArrayTail<TArray> extends infer Result
|
||||
? ResolvedOptions['preserveReadonly'] extends true
|
||||
? IfArrayReadonly<TArray, Readonly<Result>, Result>
|
||||
: Result
|
||||
: never // Should never happen
|
||||
: never // Should never happen
|
||||
: never; // Should never happen
|
||||
|
||||
type _ArrayTail<TArray extends UnknownArray> = TArray extends readonly [unknown?, ...infer Tail]
|
||||
? keyof TArray & `${number}` extends never
|
||||
? []
|
||||
: Tail
|
||||
: [];
|
22
node_modules/type-fest/source/array-values.d.ts
generated
vendored
Normal file
22
node_modules/type-fest/source/array-values.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
Provides all values for a constant array or tuple.
|
||||
|
||||
Use-case: This type is useful when working with constant arrays or tuples and you want to enforce type-safety with their values.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ArrayValues, ArrayIndices} from 'type-fest';
|
||||
|
||||
const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as const;
|
||||
|
||||
type WeekdayName = ArrayValues<typeof weekdays>;
|
||||
type Weekday = ArrayIndices<typeof weekdays>;
|
||||
|
||||
const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
|
||||
```
|
||||
|
||||
@see {@link ArrayIndices}
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type ArrayValues<T extends readonly unknown[]> = T[number];
|
29
node_modules/type-fest/source/arrayable.d.ts
generated
vendored
Normal file
29
node_modules/type-fest/source/arrayable.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
Create a type that represents either the value or an array of the value.
|
||||
|
||||
@see Promisable
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Arrayable} from 'type-fest';
|
||||
|
||||
function bundle(input: string, output: Arrayable<string>) {
|
||||
const outputList = Array.isArray(output) ? output : [output];
|
||||
|
||||
// …
|
||||
|
||||
for (const output of outputList) {
|
||||
console.log(`write to: ${output}`);
|
||||
}
|
||||
}
|
||||
|
||||
bundle('src/index.js', 'dist/index.js');
|
||||
bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
|
||||
```
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type Arrayable<T> =
|
||||
T
|
||||
// TODO: Use `readonly T[]` when this issue is resolved: https://github.com/microsoft/TypeScript/issues/17002
|
||||
| T[];
|
23
node_modules/type-fest/source/async-return-type.d.ts
generated
vendored
Normal file
23
node_modules/type-fest/source/async-return-type.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
type AsyncFunction = (...arguments_: any[]) => PromiseLike<unknown>;
|
||||
|
||||
/**
|
||||
Unwrap the return type of a function that returns a `Promise`.
|
||||
|
||||
There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.
|
||||
|
||||
@example
|
||||
```ts
|
||||
import type {AsyncReturnType} from 'type-fest';
|
||||
import {asyncFunction} from 'api';
|
||||
|
||||
// This type resolves to the unwrapped return type of `asyncFunction`.
|
||||
type Value = AsyncReturnType<typeof asyncFunction>;
|
||||
|
||||
async function doSomething(value: Value) {}
|
||||
|
||||
asyncFunction().then(value => doSomething(value));
|
||||
```
|
||||
|
||||
@category Async
|
||||
*/
|
||||
export type AsyncReturnType<Target extends AsyncFunction> = Awaited<ReturnType<Target>>;
|
32
node_modules/type-fest/source/asyncify.d.ts
generated
vendored
Normal file
32
node_modules/type-fest/source/asyncify.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import type {SetReturnType} from './set-return-type';
|
||||
|
||||
/**
|
||||
Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
|
||||
|
||||
Use-case: You have two functions, one synchronous and one asynchronous that do the same thing. Instead of having to duplicate the type definition, you can use `Asyncify` to reuse the synchronous type.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Asyncify} from 'type-fest';
|
||||
|
||||
// Synchronous function.
|
||||
function getFooSync(someArg: SomeType): Foo {
|
||||
// …
|
||||
}
|
||||
|
||||
type AsyncifiedFooGetter = Asyncify<typeof getFooSync>;
|
||||
//=> type AsyncifiedFooGetter = (someArg: SomeType) => Promise<Foo>;
|
||||
|
||||
// Same as `getFooSync` but asynchronous.
|
||||
const getFooAsync: AsyncifiedFooGetter = (someArg) => {
|
||||
// TypeScript now knows that `someArg` is `SomeType` automatically.
|
||||
// It also knows that this function must return `Promise<Foo>`.
|
||||
// If you have `@typescript-eslint/promise-function-async` linter rule enabled, it will even report that "Functions that return promises must be async.".
|
||||
|
||||
// …
|
||||
}
|
||||
```
|
||||
|
||||
@category Async
|
||||
*/
|
||||
export type Asyncify<Function_ extends (...arguments_: any[]) => any> = SetReturnType<Function_, Promise<Awaited<ReturnType<Function_>>>>;
|
68
node_modules/type-fest/source/basic.d.ts
generated
vendored
Normal file
68
node_modules/type-fest/source/basic.d.ts
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
||||
|
||||
@category Class
|
||||
*/
|
||||
export type Class<T, Arguments extends unknown[] = any[]> = {
|
||||
prototype: Pick<T, keyof T>;
|
||||
new(...arguments_: Arguments): T;
|
||||
};
|
||||
|
||||
/**
|
||||
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
||||
|
||||
@category Class
|
||||
*/
|
||||
export type Constructor<T, Arguments extends unknown[] = any[]> = new(...arguments_: Arguments) => T;
|
||||
|
||||
/**
|
||||
Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/classes.html#abstract-classes).
|
||||
|
||||
@category Class
|
||||
|
||||
@privateRemarks
|
||||
We cannot use a `type` here because TypeScript throws: 'abstract' modifier cannot appear on a type member. (1070)
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface AbstractClass<T, Arguments extends unknown[] = any[]> extends AbstractConstructor<T, Arguments> {
|
||||
prototype: Pick<T, keyof T>;
|
||||
}
|
||||
|
||||
/**
|
||||
Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures) constructor.
|
||||
|
||||
@category Class
|
||||
*/
|
||||
export type AbstractConstructor<T, Arguments extends unknown[] = any[]> = abstract new(...arguments_: Arguments) => T;
|
||||
|
||||
/**
|
||||
Matches a JSON object.
|
||||
|
||||
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
||||
|
||||
@category JSON
|
||||
*/
|
||||
export type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
|
||||
|
||||
/**
|
||||
Matches a JSON array.
|
||||
|
||||
@category JSON
|
||||
*/
|
||||
export type JsonArray = JsonValue[] | readonly JsonValue[];
|
||||
|
||||
/**
|
||||
Matches any valid JSON primitive value.
|
||||
|
||||
@category JSON
|
||||
*/
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
|
||||
/**
|
||||
Matches any valid JSON value.
|
||||
|
||||
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
|
||||
|
||||
@category JSON
|
||||
*/
|
||||
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
89
node_modules/type-fest/source/camel-case.d.ts
generated
vendored
Normal file
89
node_modules/type-fest/source/camel-case.d.ts
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {Words} from './words';
|
||||
|
||||
/**
|
||||
CamelCase options.
|
||||
|
||||
@see {@link CamelCase}
|
||||
*/
|
||||
export type CamelCaseOptions = {
|
||||
/**
|
||||
Whether to preserved consecutive uppercase letter.
|
||||
|
||||
@default true
|
||||
*/
|
||||
preserveConsecutiveUppercase?: boolean;
|
||||
};
|
||||
|
||||
export type DefaultCamelCaseOptions = {
|
||||
preserveConsecutiveUppercase: true;
|
||||
};
|
||||
|
||||
/**
|
||||
Convert an array of words to camel-case.
|
||||
*/
|
||||
type CamelCaseFromArray<
|
||||
Words extends string[],
|
||||
Options extends Required<CamelCaseOptions>,
|
||||
OutputString extends string = '',
|
||||
> = Words extends [
|
||||
infer FirstWord extends string,
|
||||
...infer RemainingWords extends string[],
|
||||
]
|
||||
? Options['preserveConsecutiveUppercase'] extends true
|
||||
? `${Capitalize<FirstWord>}${CamelCaseFromArray<RemainingWords, Options>}`
|
||||
: `${Capitalize<Lowercase<FirstWord>>}${CamelCaseFromArray<RemainingWords, Options>}`
|
||||
: OutputString;
|
||||
|
||||
/**
|
||||
Convert a string literal to camel-case.
|
||||
|
||||
This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result.
|
||||
|
||||
By default, consecutive uppercase letter are preserved. See {@link CamelCaseOptions.preserveConsecutiveUppercase preserveConsecutiveUppercase} option to change this behaviour.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {CamelCase} from 'type-fest';
|
||||
|
||||
// Simple
|
||||
|
||||
const someVariable: CamelCase<'foo-bar'> = 'fooBar';
|
||||
const preserveConsecutiveUppercase: CamelCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'fooBARBaz';
|
||||
|
||||
// Advanced
|
||||
|
||||
type CamelCasedProperties<T> = {
|
||||
[K in keyof T as CamelCase<K>]: T[K]
|
||||
};
|
||||
|
||||
interface RawOptions {
|
||||
'dry-run': boolean;
|
||||
'full_family_name': string;
|
||||
foo: number;
|
||||
BAR: string;
|
||||
QUZ_QUX: number;
|
||||
'OTHER-FIELD': boolean;
|
||||
}
|
||||
|
||||
const dbResult: CamelCasedProperties<RawOptions> = {
|
||||
dryRun: true,
|
||||
fullFamilyName: 'bar.js',
|
||||
foo: 123,
|
||||
bar: 'foo',
|
||||
quzQux: 6,
|
||||
otherField: false
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
*/
|
||||
export type CamelCase<Type, Options extends CamelCaseOptions = {}> = Type extends string
|
||||
? string extends Type
|
||||
? Type
|
||||
: Uncapitalize<CamelCaseFromArray<
|
||||
Words<Type extends Uppercase<Type> ? Lowercase<Type> : Type>,
|
||||
ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>
|
||||
>>
|
||||
: Type;
|
97
node_modules/type-fest/source/camel-cased-properties-deep.d.ts
generated
vendored
Normal file
97
node_modules/type-fest/source/camel-cased-properties-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case';
|
||||
import type {ApplyDefaultOptions, NonRecursiveType} from './internal';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
/**
|
||||
Convert object properties to camel case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see CamelCasedProperties
|
||||
@see CamelCase
|
||||
|
||||
@example
|
||||
```
|
||||
import type {CamelCasedPropertiesDeep} from 'type-fest';
|
||||
|
||||
interface User {
|
||||
UserId: number;
|
||||
UserName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
UserInfo: User;
|
||||
UserFriends: User[];
|
||||
}
|
||||
|
||||
const result: CamelCasedPropertiesDeep<UserWithFriends> = {
|
||||
userInfo: {
|
||||
userId: 1,
|
||||
userName: 'Tom',
|
||||
},
|
||||
userFriends: [
|
||||
{
|
||||
userId: 2,
|
||||
userName: 'Jerry',
|
||||
},
|
||||
{
|
||||
userId: 3,
|
||||
userName: 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: { fooBARBiz: [{ fooBARBaz: string }] }}, {preserveConsecutiveUppercase: false}> = {
|
||||
fooBar: {
|
||||
fooBarBiz: [{
|
||||
fooBarBaz: 'string',
|
||||
}],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
@category Object
|
||||
*/
|
||||
export type CamelCasedPropertiesDeep<
|
||||
Value,
|
||||
Options extends CamelCaseOptions = {},
|
||||
> = _CamelCasedPropertiesDeep<Value, ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>>;
|
||||
|
||||
type _CamelCasedPropertiesDeep<
|
||||
Value,
|
||||
Options extends Required<CamelCaseOptions>,
|
||||
> = Value extends NonRecursiveType
|
||||
? Value
|
||||
: Value extends UnknownArray
|
||||
? CamelCasedPropertiesArrayDeep<Value, Options>
|
||||
: Value extends Set<infer U>
|
||||
? Set<_CamelCasedPropertiesDeep<U, Options>>
|
||||
: Value extends object
|
||||
? {
|
||||
[K in keyof Value as CamelCase<K, Options>]: _CamelCasedPropertiesDeep<Value[K], Options>;
|
||||
}
|
||||
: Value;
|
||||
|
||||
// This is a copy of DelimiterCasedPropertiesArrayDeep (see: delimiter-cased-properties-deep.d.ts).
|
||||
// These types should be kept in sync.
|
||||
type CamelCasedPropertiesArrayDeep<
|
||||
Value extends UnknownArray,
|
||||
Options extends Required<CamelCaseOptions>,
|
||||
> = Value extends []
|
||||
? []
|
||||
// Trailing spread array
|
||||
: Value extends [infer U, ...infer V]
|
||||
? [_CamelCasedPropertiesDeep<U, Options>, ..._CamelCasedPropertiesDeep<V, Options>]
|
||||
: Value extends readonly [infer U, ...infer V]
|
||||
? readonly [_CamelCasedPropertiesDeep<U, Options>, ..._CamelCasedPropertiesDeep<V, Options>]
|
||||
: // Leading spread array
|
||||
Value extends readonly [...infer U, infer V]
|
||||
? [..._CamelCasedPropertiesDeep<U, Options>, _CamelCasedPropertiesDeep<V, Options>]
|
||||
: // Array
|
||||
Value extends Array<infer U>
|
||||
? Array<_CamelCasedPropertiesDeep<U, Options>>
|
||||
: Value extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<_CamelCasedPropertiesDeep<U, Options>>
|
||||
: never;
|
43
node_modules/type-fest/source/camel-cased-properties.d.ts
generated
vendored
Normal file
43
node_modules/type-fest/source/camel-cased-properties.d.ts
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case';
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
|
||||
/**
|
||||
Convert object properties to camel case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see CamelCasedPropertiesDeep
|
||||
@see CamelCase
|
||||
|
||||
@example
|
||||
```
|
||||
import type {CamelCasedProperties} from 'type-fest';
|
||||
|
||||
interface User {
|
||||
UserId: number;
|
||||
UserName: string;
|
||||
}
|
||||
|
||||
const result: CamelCasedProperties<User> = {
|
||||
userId: 1,
|
||||
userName: 'Tom',
|
||||
};
|
||||
|
||||
const preserveConsecutiveUppercase: CamelCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: false}> = {
|
||||
fooBar: 'string',
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
@category Object
|
||||
*/
|
||||
export type CamelCasedProperties<Value, Options extends CamelCaseOptions = {}> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: {
|
||||
[K in keyof Value as
|
||||
CamelCase<K, ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>>
|
||||
]: Value[K];
|
||||
};
|
45
node_modules/type-fest/source/conditional-except.d.ts
generated
vendored
Normal file
45
node_modules/type-fest/source/conditional-except.d.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import type {Except} from './except';
|
||||
import type {ConditionalKeys} from './conditional-keys';
|
||||
|
||||
/**
|
||||
Exclude keys from a shape that matches the given `Condition`.
|
||||
|
||||
This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Primitive, ConditionalExcept} from 'type-fest';
|
||||
|
||||
class Awesome {
|
||||
name: string;
|
||||
successes: number;
|
||||
failures: bigint;
|
||||
|
||||
run() {}
|
||||
}
|
||||
|
||||
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
||||
//=> {run: () => void}
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ConditionalExcept} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | number;
|
||||
c: () => void;
|
||||
d: {};
|
||||
}
|
||||
|
||||
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
||||
//=> {b: string | number; c: () => void; d: {}}
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type ConditionalExcept<Base, Condition> = Except<
|
||||
Base,
|
||||
ConditionalKeys<Base, Condition>
|
||||
>;
|
47
node_modules/type-fest/source/conditional-keys.d.ts
generated
vendored
Normal file
47
node_modules/type-fest/source/conditional-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import type {IfNever} from './if-never';
|
||||
|
||||
/**
|
||||
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
||||
|
||||
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ConditionalKeys} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | number;
|
||||
c?: string;
|
||||
d: {};
|
||||
}
|
||||
|
||||
type StringKeysOnly = ConditionalKeys<Example, string>;
|
||||
//=> 'a'
|
||||
```
|
||||
|
||||
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ConditionalKeys} from 'type-fest';
|
||||
|
||||
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
||||
//=> 'a' | 'c'
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type ConditionalKeys<Base, Condition> =
|
||||
{
|
||||
// Map through all the keys of the given base type.
|
||||
[Key in keyof Base]-?:
|
||||
// Pick only keys with types extending the given `Condition` type.
|
||||
Base[Key] extends Condition
|
||||
// Retain this key
|
||||
// If the value for the key extends never, only include it if `Condition` also extends never
|
||||
? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
|
||||
// Discard this key since the condition fails.
|
||||
: never;
|
||||
// Convert the produced object into a union type of the keys which passed the conditional test.
|
||||
}[keyof Base];
|
118
node_modules/type-fest/source/conditional-pick-deep.d.ts
generated
vendored
Normal file
118
node_modules/type-fest/source/conditional-pick-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
import type {IsEqual} from './is-equal';
|
||||
import type {ConditionalExcept} from './conditional-except';
|
||||
import type {ConditionalSimplifyDeep} from './conditional-simplify';
|
||||
import type {UnknownRecord} from './unknown-record';
|
||||
import type {EmptyObject} from './empty-object';
|
||||
import type {ApplyDefaultOptions, IsPlainObject} from './internal';
|
||||
|
||||
/**
|
||||
Used to mark properties that should be excluded.
|
||||
*/
|
||||
declare const conditionalPickDeepSymbol: unique symbol;
|
||||
|
||||
/**
|
||||
Assert the condition according to the {@link ConditionalPickDeepOptions.condition|condition} option.
|
||||
*/
|
||||
type AssertCondition<Type, Condition, Options extends ConditionalPickDeepOptions> = Options['condition'] extends 'equality'
|
||||
? IsEqual<Type, Condition>
|
||||
: Type extends Condition
|
||||
? true
|
||||
: false;
|
||||
|
||||
/**
|
||||
ConditionalPickDeep options.
|
||||
|
||||
@see ConditionalPickDeep
|
||||
*/
|
||||
export type ConditionalPickDeepOptions = {
|
||||
/**
|
||||
The condition assertion mode.
|
||||
|
||||
@default 'extends'
|
||||
*/
|
||||
condition?: 'extends' | 'equality';
|
||||
};
|
||||
|
||||
type DefaultConditionalPickDeepOptions = {
|
||||
condition: 'extends';
|
||||
};
|
||||
|
||||
/**
|
||||
Pick keys recursively from the shape that matches the given condition.
|
||||
|
||||
@see ConditionalPick
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ConditionalPickDeep} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | boolean;
|
||||
c: {
|
||||
d: string;
|
||||
e: {
|
||||
f?: string;
|
||||
g?: boolean;
|
||||
h: string | boolean;
|
||||
i: boolean | bigint;
|
||||
};
|
||||
j: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
type StringPick = ConditionalPickDeep<Example, string>;
|
||||
//=> {a: string; c: {d: string}}
|
||||
|
||||
type StringPickOptional = ConditionalPickDeep<Example, string | undefined>;
|
||||
//=> {a: string; c: {d: string; e: {f?: string}}}
|
||||
|
||||
type StringPickOptionalOnly = ConditionalPickDeep<Example, string | undefined, {condition: 'equality'}>;
|
||||
//=> {c: {e: {f?: string}}}
|
||||
|
||||
type BooleanPick = ConditionalPickDeep<Example, boolean | undefined>;
|
||||
//=> {c: {e: {g?: boolean}; j: boolean}}
|
||||
|
||||
type NumberPick = ConditionalPickDeep<Example, number>;
|
||||
//=> {}
|
||||
|
||||
type StringOrBooleanPick = ConditionalPickDeep<Example, string | boolean>;
|
||||
//=> {
|
||||
// a: string;
|
||||
// b: string | boolean;
|
||||
// c: {
|
||||
// d: string;
|
||||
// e: {
|
||||
// h: string | boolean
|
||||
// };
|
||||
// j: boolean;
|
||||
// };
|
||||
// }
|
||||
|
||||
type StringOrBooleanPickOnly = ConditionalPickDeep<Example, string | boolean, {condition: 'equality'}>;
|
||||
//=> {b: string | boolean; c: {e: {h: string | boolean}}}
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type ConditionalPickDeep<
|
||||
Type,
|
||||
Condition,
|
||||
Options extends ConditionalPickDeepOptions = {},
|
||||
> = _ConditionalPickDeep<
|
||||
Type,
|
||||
Condition,
|
||||
ApplyDefaultOptions<ConditionalPickDeepOptions, DefaultConditionalPickDeepOptions, Options>
|
||||
>;
|
||||
|
||||
type _ConditionalPickDeep<
|
||||
Type,
|
||||
Condition,
|
||||
Options extends Required<ConditionalPickDeepOptions>,
|
||||
> = ConditionalSimplifyDeep<ConditionalExcept<{
|
||||
[Key in keyof Type]: AssertCondition<Type[Key], Condition, Options> extends true
|
||||
? Type[Key]
|
||||
: IsPlainObject<Type[Key]> extends true
|
||||
? _ConditionalPickDeep<Type[Key], Condition, Options>
|
||||
: typeof conditionalPickDeepSymbol;
|
||||
}, (typeof conditionalPickDeepSymbol | undefined) | EmptyObject>, never, UnknownRecord>;
|
44
node_modules/type-fest/source/conditional-pick.d.ts
generated
vendored
Normal file
44
node_modules/type-fest/source/conditional-pick.d.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import type {ConditionalKeys} from './conditional-keys';
|
||||
|
||||
/**
|
||||
Pick keys from the shape that matches the given `Condition`.
|
||||
|
||||
This is useful when you want to create a new type from a specific subset of an existing type. For example, you might want to pick all the primitive properties from a class and form a new automatically derived type.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Primitive, ConditionalPick} from 'type-fest';
|
||||
|
||||
class Awesome {
|
||||
name: string;
|
||||
successes: number;
|
||||
failures: bigint;
|
||||
|
||||
run() {}
|
||||
}
|
||||
|
||||
type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
|
||||
//=> {name: string; successes: number; failures: bigint}
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ConditionalPick} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | number;
|
||||
c: () => void;
|
||||
d: {};
|
||||
}
|
||||
|
||||
type StringKeysOnly = ConditionalPick<Example, string>;
|
||||
//=> {a: string}
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type ConditionalPick<Base, Condition> = Pick<
|
||||
Base,
|
||||
ConditionalKeys<Base, Condition>
|
||||
>;
|
32
node_modules/type-fest/source/conditional-simplify.d.ts
generated
vendored
Normal file
32
node_modules/type-fest/source/conditional-simplify.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
Simplifies a type while including and/or excluding certain types from being simplified. Useful to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
||||
|
||||
This type is **experimental** and was introduced as a result of this {@link https://github.com/sindresorhus/type-fest/issues/436 issue}. It should be used with caution.
|
||||
|
||||
@internal
|
||||
@experimental
|
||||
@see Simplify
|
||||
@category Object
|
||||
*/
|
||||
export type ConditionalSimplify<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
|
||||
? Type
|
||||
: Type extends IncludeType
|
||||
? {[TypeKey in keyof Type]: Type[TypeKey]}
|
||||
: Type;
|
||||
|
||||
/**
|
||||
Recursively simplifies a type while including and/or excluding certain types from being simplified.
|
||||
|
||||
This type is **experimental** and was introduced as a result of this {@link https://github.com/sindresorhus/type-fest/issues/436 issue}. It should be used with caution.
|
||||
|
||||
See {@link ConditionalSimplify} for usages and examples.
|
||||
|
||||
@internal
|
||||
@experimental
|
||||
@category Object
|
||||
*/
|
||||
export type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
|
||||
? Type
|
||||
: Type extends IncludeType
|
||||
? {[TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType>}
|
||||
: Type;
|
78
node_modules/type-fest/source/delimiter-case.d.ts
generated
vendored
Normal file
78
node_modules/type-fest/source/delimiter-case.d.ts
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import type {ApplyDefaultOptions, AsciiPunctuation, StartsWith} from './internal';
|
||||
import type {IsStringLiteral} from './is-literal';
|
||||
import type {Merge} from './merge';
|
||||
import type {DefaultWordsOptions, Words, WordsOptions} from './words';
|
||||
|
||||
export type DefaultDelimiterCaseOptions = Merge<DefaultWordsOptions, {splitOnNumbers: false}>;
|
||||
|
||||
/**
|
||||
Convert an array of words to delimiter case starting with a delimiter with input capitalization.
|
||||
*/
|
||||
type DelimiterCaseFromArray<
|
||||
Words extends string[],
|
||||
Delimiter extends string,
|
||||
OutputString extends string = '',
|
||||
> = Words extends [
|
||||
infer FirstWord extends string,
|
||||
...infer RemainingWords extends string[],
|
||||
]
|
||||
? DelimiterCaseFromArray<RemainingWords, Delimiter, `${OutputString}${
|
||||
StartsWith<FirstWord, AsciiPunctuation> extends true ? '' : Delimiter
|
||||
}${FirstWord}`>
|
||||
: OutputString;
|
||||
|
||||
type RemoveFirstLetter<S extends string> = S extends `${infer _}${infer Rest}`
|
||||
? Rest
|
||||
: '';
|
||||
|
||||
/**
|
||||
Convert a string literal to a custom string delimiter casing.
|
||||
|
||||
This can be useful when, for example, converting a camel-cased object property to an oddly cased one.
|
||||
|
||||
@see KebabCase
|
||||
@see SnakeCase
|
||||
|
||||
@example
|
||||
```
|
||||
import type {DelimiterCase} from 'type-fest';
|
||||
|
||||
// Simple
|
||||
|
||||
const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
|
||||
const someVariableNoSplitOnNumbers: DelimiterCase<'p2pNetwork', '#', {splitOnNumbers: false}> = 'p2p#network';
|
||||
|
||||
// Advanced
|
||||
|
||||
type OddlyCasedProperties<T> = {
|
||||
[K in keyof T as DelimiterCase<K, '#'>]: T[K]
|
||||
};
|
||||
|
||||
interface SomeOptions {
|
||||
dryRun: boolean;
|
||||
includeFile: string;
|
||||
foo: number;
|
||||
}
|
||||
|
||||
const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
||||
'dry#run': true,
|
||||
'include#file': 'bar.js',
|
||||
foo: 123
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
*/
|
||||
export type DelimiterCase<
|
||||
Value,
|
||||
Delimiter extends string,
|
||||
Options extends WordsOptions = {},
|
||||
> = Value extends string
|
||||
? IsStringLiteral<Value> extends false
|
||||
? Value
|
||||
: Lowercase<RemoveFirstLetter<DelimiterCaseFromArray<
|
||||
Words<Value, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>,
|
||||
Delimiter
|
||||
>>>
|
||||
: Value;
|
106
node_modules/type-fest/source/delimiter-cased-properties-deep.d.ts
generated
vendored
Normal file
106
node_modules/type-fest/source/delimiter-cased-properties-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case';
|
||||
import type {ApplyDefaultOptions, NonRecursiveType} from './internal';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
import type {WordsOptions} from './words';
|
||||
|
||||
/**
|
||||
Convert object properties to delimiter case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see DelimiterCase
|
||||
@see DelimiterCasedProperties
|
||||
|
||||
@example
|
||||
```
|
||||
import type {DelimiterCasedPropertiesDeep} from 'type-fest';
|
||||
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
userInfo: User;
|
||||
userFriends: User[];
|
||||
}
|
||||
|
||||
const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
|
||||
'user-info': {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
},
|
||||
'user-friends': [
|
||||
{
|
||||
'user-id': 2,
|
||||
'user-name': 'Jerry',
|
||||
},
|
||||
{
|
||||
'user-id': 3,
|
||||
'user-name': 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const splitOnNumbers: DelimiterCasedPropertiesDeep<{line1: { line2: [{ line3: string }] }}, '-', {splitOnNumbers: true}> = {
|
||||
'line-1': {
|
||||
'line-2': [
|
||||
{
|
||||
'line-3': 'string',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
@category Object
|
||||
*/
|
||||
export type DelimiterCasedPropertiesDeep<
|
||||
Value,
|
||||
Delimiter extends string,
|
||||
Options extends WordsOptions = {},
|
||||
> = _DelimiterCasedPropertiesDeep<Value, Delimiter, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
||||
|
||||
type _DelimiterCasedPropertiesDeep<
|
||||
Value,
|
||||
Delimiter extends string,
|
||||
Options extends Required<WordsOptions>,
|
||||
> = Value extends NonRecursiveType
|
||||
? Value
|
||||
: Value extends UnknownArray
|
||||
? DelimiterCasedPropertiesArrayDeep<Value, Delimiter, Options>
|
||||
: Value extends Set<infer U>
|
||||
? Set<_DelimiterCasedPropertiesDeep<U, Delimiter, Options>>
|
||||
: Value extends object
|
||||
? {
|
||||
[K in keyof Value as DelimiterCase<K, Delimiter, Options>]:
|
||||
_DelimiterCasedPropertiesDeep<Value[K], Delimiter, Options>
|
||||
}
|
||||
: Value;
|
||||
|
||||
// This is a copy of CamelCasedPropertiesArrayDeep (see: camel-cased-properties-deep.d.ts).
|
||||
// These types should be kept in sync.
|
||||
type DelimiterCasedPropertiesArrayDeep<
|
||||
Value extends UnknownArray,
|
||||
Delimiter extends string,
|
||||
Options extends Required<WordsOptions>,
|
||||
> = Value extends []
|
||||
? []
|
||||
// Trailing spread array
|
||||
: Value extends [infer U, ...infer V]
|
||||
? [_DelimiterCasedPropertiesDeep<U, Delimiter, Options>, ..._DelimiterCasedPropertiesDeep<V, Delimiter, Options>]
|
||||
: Value extends readonly [infer U, ...infer V]
|
||||
? readonly [_DelimiterCasedPropertiesDeep<U, Delimiter, Options>, ..._DelimiterCasedPropertiesDeep<V, Delimiter, Options>]
|
||||
// Leading spread array
|
||||
: Value extends [...infer U, infer V]
|
||||
? [..._DelimiterCasedPropertiesDeep<U, Delimiter, Options>, _DelimiterCasedPropertiesDeep<V, Delimiter, Options>]
|
||||
: Value extends readonly [...infer U, infer V]
|
||||
? readonly [..._DelimiterCasedPropertiesDeep<U, Delimiter, Options>, _DelimiterCasedPropertiesDeep<V, Delimiter, Options>]
|
||||
// Array
|
||||
: Value extends Array<infer U>
|
||||
? Array<_DelimiterCasedPropertiesDeep<U, Delimiter, Options>>
|
||||
: Value extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<_DelimiterCasedPropertiesDeep<U, Delimiter, Options>>
|
||||
: never;
|
46
node_modules/type-fest/source/delimiter-cased-properties.d.ts
generated
vendored
Normal file
46
node_modules/type-fest/source/delimiter-cased-properties.d.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case';
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {WordsOptions} from './words';
|
||||
|
||||
/**
|
||||
Convert object properties to delimiter case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see DelimiterCase
|
||||
@see DelimiterCasedPropertiesDeep
|
||||
|
||||
@example
|
||||
```
|
||||
import type {DelimiterCasedProperties} from 'type-fest';
|
||||
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
const result: DelimiterCasedProperties<User, '-'> = {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
};
|
||||
|
||||
const splitOnNumbers: DelimiterCasedProperties<{line1: string}, '-', {splitOnNumbers: true}> = {
|
||||
'line-1': 'string',
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
@category Object
|
||||
*/
|
||||
export type DelimiterCasedProperties<
|
||||
Value,
|
||||
Delimiter extends string,
|
||||
Options extends WordsOptions = {},
|
||||
> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: {[K in keyof Value as
|
||||
DelimiterCase<K, Delimiter, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>
|
||||
]: Value[K]};
|
89
node_modules/type-fest/source/distributed-omit.d.ts
generated
vendored
Normal file
89
node_modules/type-fest/source/distributed-omit.d.ts
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import type {KeysOfUnion} from './keys-of-union';
|
||||
|
||||
/**
|
||||
Omits keys from a type, distributing the operation over a union.
|
||||
|
||||
TypeScript's `Omit` doesn't distribute over unions, leading to the erasure of unique properties from union members when omitting keys. This creates a type that only retains properties common to all union members, making it impossible to access member-specific properties after the Omit. Essentially, using `Omit` on a union type merges the types into a less specific one, hindering type narrowing and property access based on discriminants. This type solves that.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
type A = {
|
||||
discriminant: 'A';
|
||||
foo: string;
|
||||
a: number;
|
||||
};
|
||||
|
||||
type B = {
|
||||
discriminant: 'B';
|
||||
foo: string;
|
||||
b: string;
|
||||
};
|
||||
|
||||
type Union = A | B;
|
||||
|
||||
type OmittedUnion = Omit<Union, 'foo'>;
|
||||
//=> {discriminant: 'A' | 'B'}
|
||||
|
||||
const omittedUnion: OmittedUnion = createOmittedUnion();
|
||||
|
||||
if (omittedUnion.discriminant === 'A') {
|
||||
// We would like to narrow `omittedUnion`'s type
|
||||
// to `A` here, but we can't because `Omit`
|
||||
// doesn't distribute over unions.
|
||||
|
||||
omittedUnion.a;
|
||||
//=> Error: `a` is not a property of `{discriminant: 'A' | 'B'}`
|
||||
}
|
||||
```
|
||||
|
||||
While `Except` solves this problem, it restricts the keys you can omit to the ones that are present in **ALL** union members, where `DistributedOmit` allows you to omit keys that are present in **ANY** union member.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = {
|
||||
discriminant: 'A';
|
||||
foo: string;
|
||||
a: number;
|
||||
};
|
||||
|
||||
type B = {
|
||||
discriminant: 'B';
|
||||
foo: string;
|
||||
bar: string;
|
||||
b: string;
|
||||
};
|
||||
|
||||
type C = {
|
||||
discriminant: 'C';
|
||||
bar: string;
|
||||
c: boolean;
|
||||
};
|
||||
|
||||
// Notice that `foo` exists in `A` and `B`, but not in `C`, and
|
||||
// `bar` exists in `B` and `C`, but not in `A`.
|
||||
|
||||
type Union = A | B | C;
|
||||
|
||||
type OmittedUnion = DistributedOmit<Union, 'foo' | 'bar'>;
|
||||
|
||||
const omittedUnion: OmittedUnion = createOmittedUnion();
|
||||
|
||||
if (omittedUnion.discriminant === 'A') {
|
||||
omittedUnion.a;
|
||||
//=> OK
|
||||
|
||||
omittedUnion.foo;
|
||||
//=> Error: `foo` is not a property of `{discriminant: 'A'; a: string}`
|
||||
|
||||
omittedUnion.bar;
|
||||
//=> Error: `bar` is not a property of `{discriminant: 'A'; a: string}`
|
||||
}
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type DistributedOmit<ObjectType, KeyType extends KeysOfUnion<ObjectType>> =
|
||||
ObjectType extends unknown
|
||||
? Omit<ObjectType, KeyType>
|
||||
: never;
|
85
node_modules/type-fest/source/distributed-pick.d.ts
generated
vendored
Normal file
85
node_modules/type-fest/source/distributed-pick.d.ts
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
import type {KeysOfUnion} from './keys-of-union';
|
||||
|
||||
/**
|
||||
Pick keys from a type, distributing the operation over a union.
|
||||
|
||||
TypeScript's `Pick` doesn't distribute over unions, leading to the erasure of unique properties from union members when picking keys. This creates a type that only retains properties common to all union members, making it impossible to access member-specific properties after the Pick. Essentially, using `Pick` on a union type merges the types into a less specific one, hindering type narrowing and property access based on discriminants. This type solves that.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
type A = {
|
||||
discriminant: 'A';
|
||||
foo: {
|
||||
bar: string;
|
||||
};
|
||||
};
|
||||
|
||||
type B = {
|
||||
discriminant: 'B';
|
||||
foo: {
|
||||
baz: string;
|
||||
};
|
||||
};
|
||||
|
||||
type Union = A | B;
|
||||
|
||||
type PickedUnion = Pick<Union, 'discriminant' | 'foo'>;
|
||||
//=> {discriminant: 'A' | 'B', foo: {bar: string} | {baz: string}}
|
||||
|
||||
const pickedUnion: PickedUnion = createPickedUnion();
|
||||
|
||||
if (pickedUnion.discriminant === 'A') {
|
||||
// We would like to narrow `pickedUnion`'s type
|
||||
// to `A` here, but we can't because `Pick`
|
||||
// doesn't distribute over unions.
|
||||
|
||||
pickedUnion.foo.bar;
|
||||
//=> Error: Property 'bar' does not exist on type '{bar: string} | {baz: string}'.
|
||||
}
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
type A = {
|
||||
discriminant: 'A';
|
||||
foo: {
|
||||
bar: string;
|
||||
};
|
||||
extraneous: boolean;
|
||||
};
|
||||
|
||||
type B = {
|
||||
discriminant: 'B';
|
||||
foo: {
|
||||
baz: string;
|
||||
};
|
||||
extraneous: boolean;
|
||||
};
|
||||
|
||||
// Notice that `foo.bar` exists in `A` but not in `B`.
|
||||
|
||||
type Union = A | B;
|
||||
|
||||
type PickedUnion = DistributedPick<Union, 'discriminant' | 'foo'>;
|
||||
|
||||
const pickedUnion: PickedUnion = createPickedUnion();
|
||||
|
||||
if (pickedUnion.discriminant === 'A') {
|
||||
pickedUnion.foo.bar;
|
||||
//=> OK
|
||||
|
||||
pickedUnion.extraneous;
|
||||
//=> Error: Property `extraneous` does not exist on type `Pick<A, 'discriminant' | 'foo'>`.
|
||||
|
||||
pickedUnion.foo.baz;
|
||||
//=> Error: `bar` is not a property of `{discriminant: 'A'; a: string}`.
|
||||
}
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type DistributedPick<ObjectType, KeyType extends KeysOfUnion<ObjectType>> =
|
||||
ObjectType extends unknown
|
||||
? Pick<ObjectType, Extract<KeyType, keyof ObjectType>>
|
||||
: never;
|
46
node_modules/type-fest/source/empty-object.d.ts
generated
vendored
Normal file
46
node_modules/type-fest/source/empty-object.d.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
declare const emptyObjectSymbol: unique symbol;
|
||||
|
||||
/**
|
||||
Represents a strictly empty plain object, the `{}` value.
|
||||
|
||||
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
||||
|
||||
@example
|
||||
```
|
||||
import type {EmptyObject} from 'type-fest';
|
||||
|
||||
// The following illustrates the problem with `{}`.
|
||||
const foo1: {} = {}; // Pass
|
||||
const foo2: {} = []; // Pass
|
||||
const foo3: {} = 42; // Pass
|
||||
const foo4: {} = {a: 1}; // Pass
|
||||
|
||||
// With `EmptyObject` only the first case is valid.
|
||||
const bar1: EmptyObject = {}; // Pass
|
||||
const bar2: EmptyObject = 42; // Fail
|
||||
const bar3: EmptyObject = []; // Fail
|
||||
const bar4: EmptyObject = {a: 1}; // Fail
|
||||
```
|
||||
|
||||
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type EmptyObject = {[emptyObjectSymbol]?: never};
|
||||
|
||||
/**
|
||||
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsEmptyObject} from 'type-fest';
|
||||
|
||||
type Pass = IsEmptyObject<{}>; //=> true
|
||||
type Fail = IsEmptyObject<[]>; //=> false
|
||||
type Fail = IsEmptyObject<null>; //=> false
|
||||
```
|
||||
|
||||
@see EmptyObject
|
||||
@category Object
|
||||
*/
|
||||
export type IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
47
node_modules/type-fest/source/enforce-optional.d.ts
generated
vendored
Normal file
47
node_modules/type-fest/source/enforce-optional.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import type {Simplify} from './simplify';
|
||||
|
||||
// Returns `never` if the key is optional otherwise return the key type.
|
||||
type RequiredFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
|
||||
? Type[Key] extends undefined
|
||||
? Key
|
||||
: never
|
||||
: Key;
|
||||
|
||||
// Returns `never` if the key is required otherwise return the key type.
|
||||
type OptionalFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
|
||||
? Type[Key] extends undefined
|
||||
? never
|
||||
: Key
|
||||
: never;
|
||||
|
||||
/**
|
||||
Enforce optional keys (by adding the `?` operator) for keys that have a union with `undefined`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {EnforceOptional} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: string;
|
||||
b?: string;
|
||||
c: undefined;
|
||||
d: number | undefined;
|
||||
};
|
||||
|
||||
type FooBar = EnforceOptional<Foo>;
|
||||
// => {
|
||||
// a: string;
|
||||
// b?: string;
|
||||
// c: undefined;
|
||||
// d?: number;
|
||||
// }
|
||||
```
|
||||
|
||||
@internal
|
||||
@category Object
|
||||
*/
|
||||
export type EnforceOptional<ObjectType> = Simplify<{
|
||||
[Key in keyof ObjectType as RequiredFilter<ObjectType, Key>]: ObjectType[Key]
|
||||
} & {
|
||||
[Key in keyof ObjectType as OptionalFilter<ObjectType, Key>]?: Exclude<ObjectType[Key], undefined>
|
||||
}>;
|
62
node_modules/type-fest/source/entries.d.ts
generated
vendored
Normal file
62
node_modules/type-fest/source/entries.d.ts
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
import type {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
|
||||
|
||||
type ArrayEntries<BaseType extends readonly unknown[]> = Array<ArrayEntry<BaseType>>;
|
||||
type MapEntries<BaseType> = Array<MapEntry<BaseType>>;
|
||||
type ObjectEntries<BaseType> = Array<ObjectEntry<BaseType>>;
|
||||
type SetEntries<BaseType extends Set<unknown>> = Array<SetEntry<BaseType>>;
|
||||
|
||||
/**
|
||||
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
|
||||
|
||||
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
||||
|
||||
@see `Entry` if you want to just access the type of a single entry.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Entries} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
someKey: number;
|
||||
}
|
||||
|
||||
const manipulatesEntries = (examples: Entries<Example>) => examples.map(example => [
|
||||
// Does some arbitrary processing on the key (with type information available)
|
||||
example[0].toUpperCase(),
|
||||
|
||||
// Does some arbitrary processing on the value (with type information available)
|
||||
example[1].toFixed()
|
||||
]);
|
||||
|
||||
const example: Example = {someKey: 1};
|
||||
const entries = Object.entries(example) as Entries<Example>;
|
||||
const output = manipulatesEntries(entries);
|
||||
|
||||
// Objects
|
||||
const objectExample = {a: 1};
|
||||
const objectEntries: Entries<typeof objectExample> = [['a', 1]];
|
||||
|
||||
// Arrays
|
||||
const arrayExample = ['a', 1];
|
||||
const arrayEntries: Entries<typeof arrayExample> = [[0, 'a'], [1, 1]];
|
||||
|
||||
// Maps
|
||||
const mapExample = new Map([['a', 1]]);
|
||||
const mapEntries: Entries<typeof mapExample> = [['a', 1]];
|
||||
|
||||
// Sets
|
||||
const setExample = new Set(['a', 1]);
|
||||
const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
|
||||
```
|
||||
|
||||
@category Object
|
||||
@category Map
|
||||
@category Set
|
||||
@category Array
|
||||
*/
|
||||
export type Entries<BaseType> =
|
||||
BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
|
||||
: BaseType extends Set<unknown> ? SetEntries<BaseType>
|
||||
: BaseType extends readonly unknown[] ? ArrayEntries<BaseType>
|
||||
: BaseType extends object ? ObjectEntries<BaseType>
|
||||
: never;
|
65
node_modules/type-fest/source/entry.d.ts
generated
vendored
Normal file
65
node_modules/type-fest/source/entry.d.ts
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
type MapKey<BaseType> = BaseType extends Map<infer KeyType, unknown> ? KeyType : never;
|
||||
type MapValue<BaseType> = BaseType extends Map<unknown, infer ValueType> ? ValueType : never;
|
||||
|
||||
export type ArrayEntry<BaseType extends readonly unknown[]> = [number, BaseType[number]];
|
||||
export type MapEntry<BaseType> = [MapKey<BaseType>, MapValue<BaseType>];
|
||||
export type ObjectEntry<BaseType> = [keyof BaseType, BaseType[keyof BaseType]];
|
||||
export type SetEntry<BaseType> = BaseType extends Set<infer ItemType> ? [ItemType, ItemType] : never;
|
||||
|
||||
/**
|
||||
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entry` type will return the type of that collection's entry.
|
||||
|
||||
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
||||
|
||||
@see `Entries` if you want to just access the type of the array of entries (which is the return of the `.entries()` method).
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Entry} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
someKey: number;
|
||||
}
|
||||
|
||||
const manipulatesEntry = (example: Entry<Example>) => [
|
||||
// Does some arbitrary processing on the key (with type information available)
|
||||
example[0].toUpperCase(),
|
||||
|
||||
// Does some arbitrary processing on the value (with type information available)
|
||||
example[1].toFixed(),
|
||||
];
|
||||
|
||||
const example: Example = {someKey: 1};
|
||||
const entry = Object.entries(example)[0] as Entry<Example>;
|
||||
const output = manipulatesEntry(entry);
|
||||
|
||||
// Objects
|
||||
const objectExample = {a: 1};
|
||||
const objectEntry: Entry<typeof objectExample> = ['a', 1];
|
||||
|
||||
// Arrays
|
||||
const arrayExample = ['a', 1];
|
||||
const arrayEntryString: Entry<typeof arrayExample> = [0, 'a'];
|
||||
const arrayEntryNumber: Entry<typeof arrayExample> = [1, 1];
|
||||
|
||||
// Maps
|
||||
const mapExample = new Map([['a', 1]]);
|
||||
const mapEntry: Entry<typeof mapExample> = ['a', 1];
|
||||
|
||||
// Sets
|
||||
const setExample = new Set(['a', 1]);
|
||||
const setEntryString: Entry<typeof setExample> = ['a', 'a'];
|
||||
const setEntryNumber: Entry<typeof setExample> = [1, 1];
|
||||
```
|
||||
|
||||
@category Object
|
||||
@category Map
|
||||
@category Array
|
||||
@category Set
|
||||
*/
|
||||
export type Entry<BaseType> =
|
||||
BaseType extends Map<unknown, unknown> ? MapEntry<BaseType>
|
||||
: BaseType extends Set<unknown> ? SetEntry<BaseType>
|
||||
: BaseType extends readonly unknown[] ? ArrayEntry<BaseType>
|
||||
: BaseType extends object ? ObjectEntry<BaseType>
|
||||
: never;
|
68
node_modules/type-fest/source/exact.d.ts
generated
vendored
Normal file
68
node_modules/type-fest/source/exact.d.ts
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import type {ArrayElement, ObjectValue} from './internal';
|
||||
import type {IsEqual} from './is-equal';
|
||||
import type {KeysOfUnion} from './keys-of-union';
|
||||
import type {IsUnknown} from './is-unknown';
|
||||
import type {Primitive} from './primitive';
|
||||
|
||||
/**
|
||||
Create a type from `ParameterType` and `InputType` and change keys exclusive to `InputType` to `never`.
|
||||
- Generate a list of keys that exists in `InputType` but not in `ParameterType`.
|
||||
- Mark these excess keys as `never`.
|
||||
*/
|
||||
type ExactObject<ParameterType, InputType> = {[Key in keyof ParameterType]: Exact<ParameterType[Key], ObjectValue<InputType, Key>>}
|
||||
& Record<Exclude<keyof InputType, KeysOfUnion<ParameterType>>, never>;
|
||||
|
||||
/**
|
||||
Create a type that does not allow extra properties, meaning it only allows properties that are explicitly declared.
|
||||
|
||||
This is useful for function type-guarding to reject arguments with excess properties. Due to the nature of TypeScript, it does not complain if excess properties are provided unless the provided value is an object literal.
|
||||
|
||||
*Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/12936) if you want to have this type as a built-in in TypeScript.*
|
||||
|
||||
@example
|
||||
```
|
||||
type OnlyAcceptName = {name: string};
|
||||
|
||||
function onlyAcceptName(arguments_: OnlyAcceptName) {}
|
||||
|
||||
// TypeScript complains about excess properties when an object literal is provided.
|
||||
onlyAcceptName({name: 'name', id: 1});
|
||||
//=> `id` is excess
|
||||
|
||||
// TypeScript does not complain about excess properties when the provided value is a variable (not an object literal).
|
||||
const invalidInput = {name: 'name', id: 1};
|
||||
onlyAcceptName(invalidInput); // No errors
|
||||
```
|
||||
|
||||
Having `Exact` allows TypeScript to reject excess properties.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Exact} from 'type-fest';
|
||||
|
||||
type OnlyAcceptName = {name: string};
|
||||
|
||||
function onlyAcceptNameImproved<T extends Exact<OnlyAcceptName, T>>(arguments_: T) {}
|
||||
|
||||
const invalidInput = {name: 'name', id: 1};
|
||||
onlyAcceptNameImproved(invalidInput); // Compilation error
|
||||
```
|
||||
|
||||
[Read more](https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined)
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Exact<ParameterType, InputType> =
|
||||
// Before distributing, check if the two types are equal and if so, return the parameter type immediately
|
||||
IsEqual<ParameterType, InputType> extends true ? ParameterType
|
||||
// If the parameter is a primitive, return it as is immediately to avoid it being converted to a complex type
|
||||
: ParameterType extends Primitive ? ParameterType
|
||||
// If the parameter is an unknown, return it as is immediately to avoid it being converted to a complex type
|
||||
: IsUnknown<ParameterType> extends true ? unknown
|
||||
// If the parameter is a Function, return it as is because this type is not capable of handling function, leave it to TypeScript
|
||||
: ParameterType extends Function ? ParameterType
|
||||
// Convert union of array to array of union: A[] & B[] => (A & B)[]
|
||||
: ParameterType extends unknown[] ? Array<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
|
||||
// In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
|
||||
: ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
|
||||
: ExactObject<ParameterType, InputType>;
|
108
node_modules/type-fest/source/except.d.ts
generated
vendored
Normal file
108
node_modules/type-fest/source/except.d.ts
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {IsEqual} from './is-equal';
|
||||
|
||||
/**
|
||||
Filter out keys from an object.
|
||||
|
||||
Returns `never` if `Exclude` is strictly equal to `Key`.
|
||||
Returns `never` if `Key` extends `Exclude`.
|
||||
Returns `Key` otherwise.
|
||||
|
||||
@example
|
||||
```
|
||||
type Filtered = Filter<'foo', 'foo'>;
|
||||
//=> never
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
type Filtered = Filter<'bar', string>;
|
||||
//=> never
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
type Filtered = Filter<'bar', 'foo'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
|
||||
@see {Except}
|
||||
*/
|
||||
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
||||
|
||||
type ExceptOptions = {
|
||||
/**
|
||||
Disallow assigning non-specified properties.
|
||||
|
||||
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
requireExactProps?: boolean;
|
||||
};
|
||||
|
||||
type DefaultExceptOptions = {
|
||||
requireExactProps: false;
|
||||
};
|
||||
|
||||
/**
|
||||
Create a type from an object type without certain keys.
|
||||
|
||||
We recommend setting the `requireExactProps` option to `true`.
|
||||
|
||||
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
||||
|
||||
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)).
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Except} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: number;
|
||||
b: string;
|
||||
};
|
||||
|
||||
type FooWithoutA = Except<Foo, 'a'>;
|
||||
//=> {b: string}
|
||||
|
||||
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
||||
//=> errors: 'a' does not exist in type '{ b: string; }'
|
||||
|
||||
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
||||
//=> {a: number} & Partial<Record<"b", never>>
|
||||
|
||||
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
||||
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
||||
|
||||
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
||||
|
||||
// Consider the following example:
|
||||
|
||||
type UserData = {
|
||||
[metadata: string]: string;
|
||||
email: string;
|
||||
name: string;
|
||||
role: 'admin' | 'user';
|
||||
};
|
||||
|
||||
// `Omit` clearly doesn't behave as expected in this case:
|
||||
type PostPayload = Omit<UserData, 'email'>;
|
||||
//=> type PostPayload = { [x: string]: string; [x: number]: string; }
|
||||
|
||||
// In situations like this, `Except` works better.
|
||||
// It simply removes the `email` key while preserving all the other keys.
|
||||
type PostPayload = Except<UserData, 'email'>;
|
||||
//=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
|
||||
_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
||||
|
||||
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
|
||||
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
||||
} & (Options['requireExactProps'] extends true
|
||||
? Partial<Record<KeysType, never>>
|
||||
: {});
|
64
node_modules/type-fest/source/find-global-type.d.ts
generated
vendored
Normal file
64
node_modules/type-fest/source/find-global-type.d.ts
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
Tries to find the type of a global with the given name.
|
||||
|
||||
Limitations: Due to peculiarities with the behavior of `globalThis`, "globally defined" only includes `var` declarations in `declare global` blocks, not `let` or `const` declarations.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {FindGlobalType} from 'type-fest';
|
||||
|
||||
declare global {
|
||||
const foo: number; // let and const don't work
|
||||
var bar: string; // var works
|
||||
}
|
||||
|
||||
type FooType = FindGlobalType<'foo'> //=> never (let/const don't work)
|
||||
type BarType = FindGlobalType<'bar'> //=> string
|
||||
type OtherType = FindGlobalType<'other'> //=> never (no global named 'other')
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type FindGlobalType<Name extends string> = typeof globalThis extends Record<Name, infer T> ? T : never;
|
||||
|
||||
/**
|
||||
Tries to find one or more types from their globally-defined constructors.
|
||||
|
||||
Use-case: Conditionally referencing DOM types only when the DOM library present.
|
||||
|
||||
*Limitations:* Due to peculiarities with the behavior of `globalThis`, "globally defined" has a narrow definition in this case. Declaring a class in a `declare global` block won't work, instead you must declare its type using an interface and declare its constructor as a `var` (*not* `let`/`const`) inside the `declare global` block.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {FindGlobalInstanceType} from 'type-fest';
|
||||
|
||||
class Point {
|
||||
constructor(public x: number, public y: number) {}
|
||||
}
|
||||
|
||||
type PointLike = Point | FindGlobalInstanceType<'DOMPoint'>;
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {FindGlobalInstanceType} from 'type-fest';
|
||||
|
||||
declare global {
|
||||
// Class syntax won't add the key to `globalThis`
|
||||
class Foo {}
|
||||
|
||||
// interface + constructor style works
|
||||
interface Bar {}
|
||||
var Bar: new () => Bar; // Not let or const
|
||||
}
|
||||
|
||||
type FindFoo = FindGlobalInstanceType<'Foo'>; // Doesn't work
|
||||
type FindBar = FindGlobalInstanceType<'Bar'>; // Works
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type FindGlobalInstanceType<Name extends string> =
|
||||
Name extends string
|
||||
? typeof globalThis extends Record<Name, abstract new (...arguments: any[]) => infer T> ? T : never
|
||||
: never;
|
43
node_modules/type-fest/source/fixed-length-array.d.ts
generated
vendored
Normal file
43
node_modules/type-fest/source/fixed-length-array.d.ts
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
Methods to exclude.
|
||||
*/
|
||||
type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';
|
||||
|
||||
/**
|
||||
Create a type that represents an array of the given type and length. The array's length and the `Array` prototype methods that manipulate its length are excluded in the resulting type.
|
||||
|
||||
Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similar type built into TypeScript.
|
||||
|
||||
Use-cases:
|
||||
- Declaring fixed-length tuples or arrays with a large number of items.
|
||||
- Creating a range union (for example, `0 | 1 | 2 | 3 | 4` from the keys of such a type) without having to resort to recursive types.
|
||||
- Creating an array of coordinates with a static length, for example, length of 3 for a 3D vector.
|
||||
|
||||
Note: This type does not prevent out-of-bounds access. Prefer `ReadonlyTuple` unless you need mutability.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {FixedLengthArray} from 'type-fest';
|
||||
|
||||
type FencingTeam = FixedLengthArray<string, 3>;
|
||||
|
||||
const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];
|
||||
|
||||
const homeFencingTeam: FencingTeam = ['George', 'John'];
|
||||
//=> error TS2322: Type string[] is not assignable to type 'FencingTeam'
|
||||
|
||||
guestFencingTeam.push('Sam');
|
||||
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
|
||||
```
|
||||
|
||||
@category Array
|
||||
@see ReadonlyTuple
|
||||
*/
|
||||
export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
|
||||
ArrayPrototype,
|
||||
Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys>
|
||||
> & {
|
||||
[index: number]: Element;
|
||||
[Symbol.iterator]: () => IterableIterator<Element>;
|
||||
readonly length: Length;
|
||||
};
|
219
node_modules/type-fest/source/get.d.ts
generated
vendored
Normal file
219
node_modules/type-fest/source/get.d.ts
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
import type {ApplyDefaultOptions, StringDigit, ToString} from './internal';
|
||||
import type {LiteralStringUnion} from './literal-union';
|
||||
import type {Paths} from './paths';
|
||||
import type {Split} from './split';
|
||||
import type {StringKeyOf} from './string-key-of';
|
||||
|
||||
type GetOptions = {
|
||||
/**
|
||||
Include `undefined` in the return type when accessing properties.
|
||||
|
||||
Setting this to `false` is not recommended.
|
||||
|
||||
@default true
|
||||
*/
|
||||
strict?: boolean;
|
||||
};
|
||||
|
||||
type DefaultGetOptions = {
|
||||
strict: true;
|
||||
};
|
||||
|
||||
/**
|
||||
Like the `Get` type but receives an array of strings as a path parameter.
|
||||
*/
|
||||
type GetWithPath<BaseType, Keys, Options extends Required<GetOptions>> =
|
||||
Keys extends readonly []
|
||||
? BaseType
|
||||
: Keys extends readonly [infer Head, ...infer Tail]
|
||||
? GetWithPath<
|
||||
PropertyOf<BaseType, Extract<Head, string>, Options>,
|
||||
Extract<Tail, string[]>,
|
||||
Options
|
||||
>
|
||||
: never;
|
||||
|
||||
/**
|
||||
Adds `undefined` to `Type` if `strict` is enabled.
|
||||
*/
|
||||
type Strictify<Type, Options extends Required<GetOptions>> =
|
||||
Options['strict'] extends false ? Type : (Type | undefined);
|
||||
|
||||
/**
|
||||
If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
|
||||
|
||||
Known limitations:
|
||||
- Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
|
||||
*/
|
||||
type StrictPropertyOf<BaseType, Key extends keyof BaseType, Options extends Required<GetOptions>> =
|
||||
Record<string, any> extends BaseType
|
||||
? string extends keyof BaseType
|
||||
? Strictify<BaseType[Key], Options> // Record<string, any>
|
||||
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
||||
: BaseType[Key];
|
||||
|
||||
/**
|
||||
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
||||
|
||||
@example
|
||||
```
|
||||
ToPath<'foo.bar.baz'>
|
||||
//=> ['foo', 'bar', 'baz']
|
||||
|
||||
ToPath<'foo[0].bar.baz'>
|
||||
//=> ['foo', '0', 'bar', 'baz']
|
||||
```
|
||||
*/
|
||||
type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
|
||||
|
||||
/**
|
||||
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
||||
*/
|
||||
type FixPathSquareBrackets<Path extends string> =
|
||||
Path extends `[${infer Head}]${infer Tail}`
|
||||
? Tail extends `[${string}`
|
||||
? `${Head}.${FixPathSquareBrackets<Tail>}`
|
||||
: `${Head}${FixPathSquareBrackets<Tail>}`
|
||||
: Path extends `${infer Head}[${infer Middle}]${infer Tail}`
|
||||
? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
|
||||
: Path;
|
||||
|
||||
/**
|
||||
Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
|
||||
|
||||
@example
|
||||
```
|
||||
ConsistsOnlyOf<'aaa', 'a'> //=> true
|
||||
ConsistsOnlyOf<'ababab', 'ab'> //=> true
|
||||
ConsistsOnlyOf<'aBa', 'a'> //=> false
|
||||
ConsistsOnlyOf<'', 'a'> //=> true
|
||||
```
|
||||
*/
|
||||
type ConsistsOnlyOf<LongString extends string, Substring extends string> =
|
||||
LongString extends ''
|
||||
? true
|
||||
: LongString extends `${Substring}${infer Tail}`
|
||||
? ConsistsOnlyOf<Tail, Substring>
|
||||
: false;
|
||||
|
||||
/**
|
||||
Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
|
||||
|
||||
@example
|
||||
```
|
||||
type WithNumbers = {foo: string; 0: boolean};
|
||||
type WithStrings = WithStringKeys<WithNumbers>;
|
||||
|
||||
type WithNumbersKeys = keyof WithNumbers;
|
||||
//=> 'foo' | 0
|
||||
type WithStringsKeys = keyof WithStrings;
|
||||
//=> 'foo' | '0'
|
||||
```
|
||||
*/
|
||||
type WithStringKeys<BaseType> = {
|
||||
[Key in StringKeyOf<BaseType>]: UncheckedIndex<BaseType, Key>
|
||||
};
|
||||
|
||||
/**
|
||||
Perform a `T[U]` operation if `T` supports indexing.
|
||||
*/
|
||||
type UncheckedIndex<T, U extends string | number> = [T] extends [Record<string | number, any>] ? T[U] : never;
|
||||
|
||||
/**
|
||||
Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
|
||||
|
||||
Note:
|
||||
- Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
|
||||
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
||||
*/
|
||||
type PropertyOf<BaseType, Key extends string, Options extends Required<GetOptions>> =
|
||||
BaseType extends null | undefined
|
||||
? undefined
|
||||
: Key extends keyof BaseType
|
||||
? StrictPropertyOf<BaseType, Key, Options>
|
||||
// Handle arrays and tuples
|
||||
: BaseType extends readonly unknown[]
|
||||
? Key extends `${number}`
|
||||
// For arrays with unknown length (regular arrays)
|
||||
? number extends BaseType['length']
|
||||
? Strictify<BaseType[number], Options>
|
||||
// For tuples: check if the index is valid
|
||||
: Key extends keyof BaseType
|
||||
? Strictify<BaseType[Key & keyof BaseType], Options>
|
||||
// Out-of-bounds access for tuples
|
||||
: unknown
|
||||
// Non-numeric string key for arrays/tuples
|
||||
: unknown
|
||||
// Handle array-like objects
|
||||
: BaseType extends {
|
||||
[n: number]: infer Item;
|
||||
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
||||
}
|
||||
? (
|
||||
ConsistsOnlyOf<Key, StringDigit> extends true
|
||||
? Strictify<Item, Options>
|
||||
: unknown
|
||||
)
|
||||
: Key extends keyof WithStringKeys<BaseType>
|
||||
? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
|
||||
: unknown;
|
||||
|
||||
// This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
|
||||
/**
|
||||
Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
|
||||
|
||||
Use-case: Retrieve a property from deep inside an API response or some other complex object.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Get} from 'type-fest';
|
||||
import * as lodash from 'lodash';
|
||||
|
||||
const get = <BaseType, Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path> =>
|
||||
lodash.get(object, path);
|
||||
|
||||
interface ApiResponse {
|
||||
hits: {
|
||||
hits: Array<{
|
||||
_id: string
|
||||
_source: {
|
||||
name: Array<{
|
||||
given: string[]
|
||||
family: string
|
||||
}>
|
||||
birthDate: string
|
||||
}
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
const getName = (apiResponse: ApiResponse) =>
|
||||
get(apiResponse, 'hits.hits[0]._source.name');
|
||||
//=> Array<{given: string[]; family: string}> | undefined
|
||||
|
||||
// Path also supports a readonly array of strings
|
||||
const getNameWithPathArray = (apiResponse: ApiResponse) =>
|
||||
get(apiResponse, ['hits','hits', '0', '_source', 'name'] as const);
|
||||
//=> Array<{given: string[]; family: string}> | undefined
|
||||
|
||||
// Non-strict mode:
|
||||
Get<string[], '3', {strict: false}> //=> string
|
||||
Get<Record<string, string>, 'foo', {strict: true}> // => string
|
||||
```
|
||||
|
||||
@category Object
|
||||
@category Array
|
||||
@category Template literal
|
||||
*/
|
||||
export type Get<
|
||||
BaseType,
|
||||
Path extends
|
||||
| readonly string[]
|
||||
| LiteralStringUnion<ToString<Paths<BaseType, {bracketNotation: false; maxRecursionDepth: 2}> | Paths<BaseType, {bracketNotation: true; maxRecursionDepth: 2}>>>,
|
||||
Options extends GetOptions = {},
|
||||
> =
|
||||
GetWithPath<
|
||||
BaseType,
|
||||
Path extends string ? ToPath<Path> : Path,
|
||||
ApplyDefaultOptions<GetOptions, DefaultGetOptions, Options>
|
||||
>;
|
21
node_modules/type-fest/source/global-this.d.ts
generated
vendored
Normal file
21
node_modules/type-fest/source/global-this.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
Declare locally scoped properties on `globalThis`.
|
||||
|
||||
When defining a global variable in a declaration file is inappropriate, it can be helpful to define a `type` or `interface` (say `ExtraGlobals`) with the global variable and then cast `globalThis` via code like `globalThis as unknown as ExtraGlobals`.
|
||||
|
||||
Instead of casting through `unknown`, you can update your `type` or `interface` to extend `GlobalThis` and then directly cast `globalThis`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {GlobalThis} from 'type-fest';
|
||||
|
||||
type ExtraGlobals = GlobalThis & {
|
||||
readonly GLOBAL_TOKEN: string;
|
||||
};
|
||||
|
||||
(globalThis as ExtraGlobals).GLOBAL_TOKEN;
|
||||
```
|
||||
|
||||
@category Type
|
||||
*/
|
||||
export type GlobalThis = typeof globalThis;
|
22
node_modules/type-fest/source/greater-than-or-equal.d.ts
generated
vendored
Normal file
22
node_modules/type-fest/source/greater-than-or-equal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import type {GreaterThan} from './greater-than';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether a given number is greater than or equal to another number.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {GreaterThanOrEqual} from 'type-fest';
|
||||
|
||||
GreaterThanOrEqual<1, -5>;
|
||||
//=> true
|
||||
|
||||
GreaterThanOrEqual<1, 1>;
|
||||
//=> true
|
||||
|
||||
GreaterThanOrEqual<1, 5>;
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B
|
||||
? never
|
||||
: A extends B ? true : GreaterThan<A, B>;
|
56
node_modules/type-fest/source/greater-than.d.ts
generated
vendored
Normal file
56
node_modules/type-fest/source/greater-than.d.ts
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import type {NumberAbsolute, PositiveNumericStringGt} from './internal';
|
||||
import type {IsEqual} from './is-equal';
|
||||
import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
|
||||
import type {And} from './and';
|
||||
import type {Or} from './or';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether a given number is greater than another number.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {GreaterThan} from 'type-fest';
|
||||
|
||||
GreaterThan<1, -5>;
|
||||
//=> true
|
||||
|
||||
GreaterThan<1, 1>;
|
||||
//=> false
|
||||
|
||||
GreaterThan<1, 5>;
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
export type GreaterThan<A extends number, B extends number> =
|
||||
A extends number // For distributing `A`
|
||||
? B extends number // For distributing `B`
|
||||
? number extends A | B
|
||||
? never
|
||||
: [
|
||||
IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
|
||||
IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
|
||||
] extends infer R extends [boolean, boolean, boolean, boolean]
|
||||
? Or<
|
||||
And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
|
||||
And<IsEqual<R[3], true>, IsEqual<R[1], false>>
|
||||
> extends true
|
||||
? true
|
||||
: Or<
|
||||
And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
|
||||
And<IsEqual<R[2], true>, IsEqual<R[0], false>>
|
||||
> extends true
|
||||
? false
|
||||
: true extends R[number]
|
||||
? false
|
||||
: [IsNegative<A>, IsNegative<B>] extends infer R extends [boolean, boolean]
|
||||
? [true, false] extends R
|
||||
? false
|
||||
: [false, true] extends R
|
||||
? true
|
||||
: [false, false] extends R
|
||||
? PositiveNumericStringGt<`${A}`, `${B}`>
|
||||
: PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`>
|
||||
: never
|
||||
: never
|
||||
: never // Should never happen
|
||||
: never; // Should never happen
|
21
node_modules/type-fest/source/has-optional-keys.d.ts
generated
vendored
Normal file
21
node_modules/type-fest/source/has-optional-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import type {OptionalKeysOf} from './optional-keys-of';
|
||||
|
||||
/**
|
||||
Creates a type that represents `true` or `false` depending on whether the given type has any optional fields.
|
||||
|
||||
This is useful when you want to create an API whose behavior depends on the presence or absence of optional fields.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {HasOptionalKeys, OptionalKeysOf} from 'type-fest';
|
||||
|
||||
type UpdateService<Entity extends object> = {
|
||||
removeField: HasOptionalKeys<Entity> extends true
|
||||
? (field: OptionalKeysOf<Entity>) => Promise<void>
|
||||
: never
|
||||
}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type HasOptionalKeys<BaseType extends object> = OptionalKeysOf<BaseType> extends never ? false : true;
|
21
node_modules/type-fest/source/has-readonly-keys.d.ts
generated
vendored
Normal file
21
node_modules/type-fest/source/has-readonly-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import type {ReadonlyKeysOf} from './readonly-keys-of';
|
||||
|
||||
/**
|
||||
Creates a type that represents `true` or `false` depending on whether the given type has any readonly fields.
|
||||
|
||||
This is useful when you want to create an API whose behavior depends on the presence or absence of readonly fields.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {HasReadonlyKeys, ReadonlyKeysOf} from 'type-fest';
|
||||
|
||||
type UpdateService<Entity extends object> = {
|
||||
removeField: HasReadonlyKeys<Entity> extends true
|
||||
? (field: ReadonlyKeysOf<Entity>) => Promise<void>
|
||||
: never
|
||||
}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type HasReadonlyKeys<BaseType extends object> = ReadonlyKeysOf<BaseType> extends never ? false : true;
|
59
node_modules/type-fest/source/has-required-keys.d.ts
generated
vendored
Normal file
59
node_modules/type-fest/source/has-required-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import type {RequiredKeysOf} from './required-keys-of';
|
||||
|
||||
/**
|
||||
Creates a type that represents `true` or `false` depending on whether the given type has any required fields.
|
||||
|
||||
This is useful when you want to create an API whose behavior depends on the presence or absence of required fields.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {HasRequiredKeys} from 'type-fest';
|
||||
|
||||
type GeneratorOptions<Template extends object> = {
|
||||
prop1: number;
|
||||
prop2: string;
|
||||
} & (HasRequiredKeys<Template> extends true
|
||||
? {template: Template}
|
||||
: {template?: Template});
|
||||
|
||||
interface Template1 {
|
||||
optionalSubParam?: string;
|
||||
}
|
||||
|
||||
interface Template2 {
|
||||
requiredSubParam: string;
|
||||
}
|
||||
|
||||
type Options1 = GeneratorOptions<Template1>;
|
||||
type Options2 = GeneratorOptions<Template2>;
|
||||
|
||||
const optA: Options1 = {
|
||||
prop1: 0,
|
||||
prop2: 'hi'
|
||||
};
|
||||
const optB: Options1 = {
|
||||
prop1: 0,
|
||||
prop2: 'hi',
|
||||
template: {}
|
||||
};
|
||||
const optC: Options1 = {
|
||||
prop1: 0,
|
||||
prop2: 'hi',
|
||||
template: {
|
||||
optionalSubParam: 'optional value'
|
||||
}
|
||||
};
|
||||
|
||||
const optD: Options2 = {
|
||||
prop1: 0,
|
||||
prop2: 'hi',
|
||||
template: {
|
||||
requiredSubParam: 'required value'
|
||||
}
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
21
node_modules/type-fest/source/has-writable-keys.d.ts
generated
vendored
Normal file
21
node_modules/type-fest/source/has-writable-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import type {WritableKeysOf} from './writable-keys-of';
|
||||
|
||||
/**
|
||||
Creates a type that represents `true` or `false` depending on whether the given type has any writable fields.
|
||||
|
||||
This is useful when you want to create an API whose behavior depends on the presence or absence of writable fields.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {HasWritableKeys, WritableKeysOf} from 'type-fest';
|
||||
|
||||
type UpdateService<Entity extends object> = {
|
||||
removeField: HasWritableKeys<Entity> extends true
|
||||
? (field: WritableKeysOf<Entity>) => Promise<void>
|
||||
: never
|
||||
}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type HasWritableKeys<BaseType extends object> = WritableKeysOf<BaseType> extends never ? false : true;
|
24
node_modules/type-fest/source/if-any.d.ts
generated
vendored
Normal file
24
node_modules/type-fest/source/if-any.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type {IsAny} from './is-any';
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given type is `any`.
|
||||
|
||||
@see {@link IsAny}
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IfAny} from 'type-fest';
|
||||
|
||||
type ShouldBeTrue = IfAny<any>;
|
||||
//=> true
|
||||
|
||||
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
||||
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
|
||||
);
|
26
node_modules/type-fest/source/if-empty-object.d.ts
generated
vendored
Normal file
26
node_modules/type-fest/source/if-empty-object.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type {IsEmptyObject} from './empty-object';
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given type is `{}`.
|
||||
|
||||
@see {@link IsEmptyObject}
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IfEmptyObject} from 'type-fest';
|
||||
|
||||
type ShouldBeTrue = IfEmptyObject<{}>;
|
||||
//=> true
|
||||
|
||||
type ShouldBeBar = IfEmptyObject<{key: any}, 'foo', 'bar'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IfEmptyObject<
|
||||
T,
|
||||
TypeIfEmptyObject = true,
|
||||
TypeIfNotEmptyObject = false,
|
||||
> = IsEmptyObject<T> extends true ? TypeIfEmptyObject : TypeIfNotEmptyObject;
|
24
node_modules/type-fest/source/if-never.d.ts
generated
vendored
Normal file
24
node_modules/type-fest/source/if-never.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type {IsNever} from './is-never';
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given type is `never`.
|
||||
|
||||
@see {@link IsNever}
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IfNever} from 'type-fest';
|
||||
|
||||
type ShouldBeTrue = IfNever<never>;
|
||||
//=> true
|
||||
|
||||
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
||||
IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
|
||||
);
|
24
node_modules/type-fest/source/if-null.d.ts
generated
vendored
Normal file
24
node_modules/type-fest/source/if-null.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type {IsNull} from './is-null';
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given type is `null`.
|
||||
|
||||
@see {@link IsNull}
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IfNull} from 'type-fest';
|
||||
|
||||
type ShouldBeTrue = IfNull<null>;
|
||||
//=> true
|
||||
|
||||
type ShouldBeBar = IfNull<'not null', 'foo', 'bar'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IfNull<T, TypeIfNull = true, TypeIfNotNull = false> = (
|
||||
IsNull<T> extends true ? TypeIfNull : TypeIfNotNull
|
||||
);
|
24
node_modules/type-fest/source/if-unknown.d.ts
generated
vendored
Normal file
24
node_modules/type-fest/source/if-unknown.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type {IsUnknown} from './is-unknown';
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given type is `unknown`.
|
||||
|
||||
@see {@link IsUnknown}
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IfUnknown} from 'type-fest';
|
||||
|
||||
type ShouldBeTrue = IfUnknown<unknown>;
|
||||
//=> true
|
||||
|
||||
type ShouldBeBar = IfUnknown<'not unknown', 'foo', 'bar'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IfUnknown<T, TypeIfUnknown = true, TypeIfNotUnknown = false> = (
|
||||
IsUnknown<T> extends true ? TypeIfUnknown : TypeIfNotUnknown
|
||||
);
|
22
node_modules/type-fest/source/includes.d.ts
generated
vendored
Normal file
22
node_modules/type-fest/source/includes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import type {IsEqual} from './is-equal';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given array includes the given item.
|
||||
|
||||
This can be useful if another type wants to make a decision based on whether the array includes that item.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Includes} from 'type-fest';
|
||||
|
||||
type hasRed<array extends any[]> = Includes<array, 'red'>;
|
||||
```
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type Includes<Value extends readonly any[], Item> =
|
||||
Value extends readonly [Value[0], ...infer rest]
|
||||
? IsEqual<Value[0], Item> extends true
|
||||
? true
|
||||
: Includes<rest, Item>
|
||||
: false;
|
35
node_modules/type-fest/source/int-closed-range.d.ts
generated
vendored
Normal file
35
node_modules/type-fest/source/int-closed-range.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import type {IntRange} from './int-range';
|
||||
import type {Sum} from './sum';
|
||||
|
||||
/**
|
||||
Generate a union of numbers.
|
||||
|
||||
The numbers are created from the given `Start` (inclusive) parameter to the given `End` (inclusive) parameter.
|
||||
|
||||
You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntClosedRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8 | 10`.
|
||||
|
||||
Note: `Start` or `End` must be non-negative and smaller than `999`.
|
||||
|
||||
Use-cases:
|
||||
1. This can be used to define a set of valid input/output values. for example:
|
||||
```
|
||||
type Age = IntClosedRange<0, 120>; //=> 0 | 1 | 2 | ... | 119 | 120
|
||||
type FontSize = IntClosedRange<10, 20>; //=> 10 | 11 | ... | 19 | 20
|
||||
type EvenNumber = IntClosedRange<0, 10, 2>; //=> 0 | 2 | 4 | 6 | 8 | 10
|
||||
```
|
||||
2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntClosedRange<0, 100>;`
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IntClosedRange} from 'type-fest';
|
||||
|
||||
// Create union type `0 | 1 | ... | 9`
|
||||
type ZeroToNine = IntClosedRange<0, 9>;
|
||||
|
||||
// Create union type `100 | 200 | 300 | ... | 900`
|
||||
type Hundreds = IntClosedRange<100, 900, 100>;
|
||||
```
|
||||
|
||||
@see IntRange
|
||||
*/
|
||||
export type IntClosedRange<Start extends number, End extends number, Skip extends number = 1> = IntRange<Start, Sum<End, 1>, Skip>;
|
55
node_modules/type-fest/source/int-range.d.ts
generated
vendored
Normal file
55
node_modules/type-fest/source/int-range.d.ts
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import type {BuildTuple} from './internal';
|
||||
import type {Subtract} from './subtract';
|
||||
|
||||
/**
|
||||
Generate a union of numbers.
|
||||
|
||||
The numbers are created from the given `Start` (inclusive) parameter to the given `End` (exclusive) parameter.
|
||||
|
||||
You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8`.
|
||||
|
||||
Note: `Start` or `End` must be non-negative and smaller than `1000`.
|
||||
|
||||
Use-cases:
|
||||
1. This can be used to define a set of valid input/output values. for example:
|
||||
```
|
||||
type Age = IntRange<0, 120>;
|
||||
type FontSize = IntRange<10, 20>;
|
||||
type EvenNumber = IntRange<0, 11, 2>; //=> 0 | 2 | 4 | 6 | 8 | 10
|
||||
```
|
||||
2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntRange<0, 100>;`
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IntRange} from 'type-fest';
|
||||
|
||||
// Create union type `0 | 1 | ... | 9`
|
||||
type ZeroToNine = IntRange<0, 10>;
|
||||
|
||||
// Create union type `100 | 200 | 300 | ... | 900`
|
||||
type Hundreds = IntRange<100, 901, 100>;
|
||||
```
|
||||
|
||||
@see IntClosedRange
|
||||
*/
|
||||
export type IntRange<Start extends number, End extends number, Step extends number = 1> = PrivateIntRange<Start, End, Step>;
|
||||
|
||||
/**
|
||||
The actual implementation of `IntRange`. It's private because it has some arguments that don't need to be exposed.
|
||||
*/
|
||||
type PrivateIntRange<
|
||||
Start extends number,
|
||||
End extends number,
|
||||
Step extends number,
|
||||
Gap extends number = Subtract<Step, 1>, // The gap between each number, gap = step - 1
|
||||
List extends unknown[] = BuildTuple<Start, never>, // The final `List` is `[...StartLengthTuple, ...[number, ...GapLengthTuple], ...[number, ...GapLengthTuple], ... ...]`, so can initialize the `List` with `[...StartLengthTuple]`
|
||||
EndLengthTuple extends unknown[] = BuildTuple<End>,
|
||||
> = Gap extends 0 ?
|
||||
// Handle the case that without `Step`
|
||||
List['length'] extends End // The result of "List[length] === End"
|
||||
? Exclude<List[number], never> // All unused elements are `never`, so exclude them
|
||||
: PrivateIntRange<Start, End, Step, Gap, [...List, List['length'] ]>
|
||||
// Handle the case that with `Step`
|
||||
: List extends [...(infer U), ...EndLengthTuple] // The result of "List[length] >= End", because the `...BuildTuple<Gap, never>` maybe make `List` too long.
|
||||
? Exclude<List[number], never>
|
||||
: PrivateIntRange<Start, End, Step, Gap, [...List, List['length'], ...BuildTuple<Gap, never>]>;
|
126
node_modules/type-fest/source/internal/array.d.ts
generated
vendored
Normal file
126
node_modules/type-fest/source/internal/array.d.ts
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
import type {IfNever} from '../if-never';
|
||||
import type {UnknownArray} from '../unknown-array';
|
||||
|
||||
/**
|
||||
Infer the length of the given array `<T>`.
|
||||
|
||||
@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
|
||||
*/
|
||||
type ArrayLength<T extends readonly unknown[]> = T extends {readonly length: infer L} ? L : never;
|
||||
|
||||
/**
|
||||
Matches any unknown array or tuple.
|
||||
*/
|
||||
export type UnknownArrayOrTuple = readonly [...unknown[]];
|
||||
// TODO: should unknown-array be updated?
|
||||
|
||||
/**
|
||||
Extracts the type of the first element of an array or tuple.
|
||||
*/
|
||||
export type FirstArrayElement<TArray extends UnknownArrayOrTuple> = TArray extends readonly [infer THead, ...unknown[]]
|
||||
? THead
|
||||
: never;
|
||||
|
||||
/**
|
||||
Extract the element of an array that also works for array union.
|
||||
|
||||
Returns `never` if T is not an array.
|
||||
|
||||
It creates a type-safe way to access the element type of `unknown` type.
|
||||
*/
|
||||
export type ArrayElement<T> = T extends readonly unknown[] ? T[0] : never;
|
||||
|
||||
/**
|
||||
Returns the static, fixed-length portion of the given array, excluding variable-length parts.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = [string, number, boolean, ...string[]];
|
||||
type B = StaticPartOfArray<A>;
|
||||
//=> [string, number, boolean]
|
||||
```
|
||||
*/
|
||||
export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = []> =
|
||||
T extends unknown
|
||||
? number extends T['length'] ?
|
||||
T extends readonly [infer U, ...infer V]
|
||||
? StaticPartOfArray<V, [...Result, U]>
|
||||
: Result
|
||||
: T
|
||||
: never; // Should never happen
|
||||
|
||||
/**
|
||||
Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = [string, number, boolean, ...string[]];
|
||||
type B = VariablePartOfArray<A>;
|
||||
//=> string[]
|
||||
```
|
||||
*/
|
||||
export type VariablePartOfArray<T extends UnknownArray> =
|
||||
T extends unknown
|
||||
? T extends readonly [...StaticPartOfArray<T>, ...infer U]
|
||||
? U
|
||||
: []
|
||||
: never; // Should never happen
|
||||
|
||||
/**
|
||||
Set the given array to readonly if `IsReadonly` is `true`, otherwise set the given array to normal, then return the result.
|
||||
|
||||
@example
|
||||
```
|
||||
type ReadonlyArray = readonly string[];
|
||||
type NormalArray = string[];
|
||||
|
||||
type ReadonlyResult = SetArrayAccess<NormalArray, true>;
|
||||
//=> readonly string[]
|
||||
|
||||
type NormalResult = SetArrayAccess<ReadonlyArray, false>;
|
||||
//=> string[]
|
||||
```
|
||||
*/
|
||||
export type SetArrayAccess<T extends UnknownArray, IsReadonly extends boolean> =
|
||||
T extends readonly [...infer U] ?
|
||||
IsReadonly extends true
|
||||
? readonly [...U]
|
||||
: [...U]
|
||||
: T;
|
||||
|
||||
/**
|
||||
Returns whether the given array `T` is readonly.
|
||||
*/
|
||||
export type IsArrayReadonly<T extends UnknownArray> = IfNever<T, false, T extends unknown[] ? false : true>;
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given array is readonly.
|
||||
|
||||
@see {@link IsArrayReadonly}
|
||||
|
||||
@example
|
||||
```
|
||||
import type {ArrayTail} from 'type-fest';
|
||||
|
||||
type ReadonlyPreservingArrayTail<TArray extends readonly unknown[]> =
|
||||
ArrayTail<TArray> extends infer Tail
|
||||
? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
|
||||
: never;
|
||||
|
||||
type ReadonlyTail = ReadonlyPreservingArrayTail<readonly [string, number, boolean]>;
|
||||
//=> readonly [number, boolean]
|
||||
|
||||
type NonReadonlyTail = ReadonlyPreservingArrayTail<[string, number, boolean]>;
|
||||
//=> [number, boolean]
|
||||
|
||||
type ShouldBeTrue = IfArrayReadonly<readonly unknown[]>;
|
||||
//=> true
|
||||
|
||||
type ShouldBeBar = IfArrayReadonly<unknown[], 'foo', 'bar'>;
|
||||
//=> 'bar'
|
||||
```
|
||||
*/
|
||||
export type IfArrayReadonly<T extends UnknownArray, TypeIfArrayReadonly = true, TypeIfNotArrayReadonly = false> =
|
||||
IsArrayReadonly<T> extends infer Result
|
||||
? Result extends true ? TypeIfArrayReadonly : TypeIfNotArrayReadonly
|
||||
: never; // Should never happen
|
67
node_modules/type-fest/source/internal/characters.d.ts
generated
vendored
Normal file
67
node_modules/type-fest/source/internal/characters.d.ts
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
export type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
||||
|
||||
export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
||||
|
||||
export type Whitespace =
|
||||
| '\u{9}' // '\t'
|
||||
| '\u{A}' // '\n'
|
||||
| '\u{B}' // '\v'
|
||||
| '\u{C}' // '\f'
|
||||
| '\u{D}' // '\r'
|
||||
| '\u{20}' // ' '
|
||||
| '\u{85}'
|
||||
| '\u{A0}'
|
||||
| '\u{1680}'
|
||||
| '\u{2000}'
|
||||
| '\u{2001}'
|
||||
| '\u{2002}'
|
||||
| '\u{2003}'
|
||||
| '\u{2004}'
|
||||
| '\u{2005}'
|
||||
| '\u{2006}'
|
||||
| '\u{2007}'
|
||||
| '\u{2008}'
|
||||
| '\u{2009}'
|
||||
| '\u{200A}'
|
||||
| '\u{2028}'
|
||||
| '\u{2029}'
|
||||
| '\u{202F}'
|
||||
| '\u{205F}'
|
||||
| '\u{3000}'
|
||||
| '\u{FEFF}';
|
||||
|
||||
export type WordSeparators = '-' | '_' | Whitespace;
|
||||
|
||||
export type AsciiPunctuation =
|
||||
| '!'
|
||||
| '"'
|
||||
| '#'
|
||||
| '$'
|
||||
| '%'
|
||||
| '&'
|
||||
| '\''
|
||||
| '('
|
||||
| ')'
|
||||
| '*'
|
||||
| '+'
|
||||
| ','
|
||||
| '-'
|
||||
| '.'
|
||||
| '/'
|
||||
| ':'
|
||||
| ';'
|
||||
| '<'
|
||||
| '='
|
||||
| '>'
|
||||
| '?'
|
||||
| '@'
|
||||
| '['
|
||||
| '\\'
|
||||
| ']'
|
||||
| '^'
|
||||
| '_'
|
||||
| '`'
|
||||
| '{'
|
||||
| '|'
|
||||
| '}'
|
||||
| '~';
|
8
node_modules/type-fest/source/internal/index.d.ts
generated
vendored
Normal file
8
node_modules/type-fest/source/internal/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export type * from './array';
|
||||
export type * from './characters';
|
||||
export type * from './keys';
|
||||
export type * from './numeric';
|
||||
export type * from './object';
|
||||
export type * from './string';
|
||||
export type * from './tuple';
|
||||
export type * from './type';
|
97
node_modules/type-fest/source/internal/keys.d.ts
generated
vendored
Normal file
97
node_modules/type-fest/source/internal/keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
import type {IsAny} from '../is-any';
|
||||
import type {IsLiteral} from '../is-literal';
|
||||
import type {ToString} from './string';
|
||||
|
||||
// Returns `never` if the key or property is not jsonable without testing whether the property is required or optional otherwise return the key.
|
||||
type BaseKeyFilter<Type, Key extends keyof Type> = Key extends symbol
|
||||
? never
|
||||
: Type[Key] extends symbol
|
||||
? never
|
||||
/*
|
||||
To prevent a problem where an object with only a `name` property is incorrectly treated as assignable to a function, we first check if the property is a record.
|
||||
This check is necessary, because without it, if we don't verify whether the property is a record, an object with a type of `{name: any}` would return `never` due to its potential assignability to a function.
|
||||
See: https://github.com/sindresorhus/type-fest/issues/657
|
||||
*/
|
||||
: Type[Key] extends Record<string, unknown>
|
||||
? Key
|
||||
: [(...arguments_: any[]) => any] extends [Type[Key]]
|
||||
? never
|
||||
: Key;
|
||||
|
||||
/**
|
||||
Returns the required keys.
|
||||
*/
|
||||
export type FilterDefinedKeys<T extends object> = Exclude<
|
||||
{
|
||||
[Key in keyof T]: IsAny<T[Key]> extends true
|
||||
? Key
|
||||
: undefined extends T[Key]
|
||||
? never
|
||||
: T[Key] extends undefined
|
||||
? never
|
||||
: BaseKeyFilter<T, Key>;
|
||||
}[keyof T],
|
||||
undefined
|
||||
>;
|
||||
|
||||
/**
|
||||
Returns the optional keys.
|
||||
*/
|
||||
export type FilterOptionalKeys<T extends object> = Exclude<
|
||||
{
|
||||
[Key in keyof T]: IsAny<T[Key]> extends true
|
||||
? never
|
||||
: undefined extends T[Key]
|
||||
? T[Key] extends undefined
|
||||
? never
|
||||
: BaseKeyFilter<T, Key>
|
||||
: never;
|
||||
}[keyof T],
|
||||
undefined
|
||||
>;
|
||||
|
||||
/**
|
||||
Disallows any of the given keys.
|
||||
*/
|
||||
export type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
||||
|
||||
/**
|
||||
Utility type to retrieve only literal keys from type.
|
||||
*/
|
||||
export type LiteralKeyOf<T> = keyof {[K in keyof T as IsLiteral<K> extends true ? K : never]-?: never};
|
||||
|
||||
/**
|
||||
Get the exact version of the given `Key` in the given object `T`.
|
||||
|
||||
Use-case: You known that a number key (e.g. 10) is in an object, but you don't know how it is defined in the object, as a string or as a number (e.g. 10 or '10'). You can use this type to get the exact version of the key. See the example.
|
||||
|
||||
@example
|
||||
```
|
||||
type Object = {
|
||||
0: number;
|
||||
'1': string;
|
||||
};
|
||||
|
||||
type Key1 = ExactKey<Object, '0'>;
|
||||
//=> 0
|
||||
type Key2 = ExactKey<Object, 0>;
|
||||
//=> 0
|
||||
|
||||
type Key3 = ExactKey<Object, '1'>;
|
||||
//=> '1'
|
||||
type Key4 = ExactKey<Object, 1>;
|
||||
//=> '1'
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type ExactKey<T extends object, Key extends PropertyKey> =
|
||||
Key extends keyof T
|
||||
? Key
|
||||
: ToString<Key> extends keyof T
|
||||
? ToString<Key>
|
||||
: Key extends `${infer NumberKey extends number}`
|
||||
? NumberKey extends keyof T
|
||||
? NumberKey
|
||||
: never
|
||||
: never;
|
118
node_modules/type-fest/source/internal/numeric.d.ts
generated
vendored
Normal file
118
node_modules/type-fest/source/internal/numeric.d.ts
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
import type {IsNever} from '../is-never';
|
||||
import type {NegativeInfinity, PositiveInfinity} from '../numeric';
|
||||
import type {UnknownArray} from '../unknown-array';
|
||||
import type {StringToNumber} from './string';
|
||||
|
||||
/**
|
||||
Returns the absolute value of a given value.
|
||||
|
||||
@example
|
||||
```
|
||||
NumberAbsolute<-1>;
|
||||
//=> 1
|
||||
|
||||
NumberAbsolute<1>;
|
||||
//=> 1
|
||||
|
||||
NumberAbsolute<NegativeInfinity>
|
||||
//=> PositiveInfinity
|
||||
```
|
||||
*/
|
||||
export type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
|
||||
|
||||
/**
|
||||
Check whether the given type is a number or a number string.
|
||||
|
||||
Supports floating-point as a string.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = IsNumberLike<'1'>;
|
||||
//=> true
|
||||
|
||||
type B = IsNumberLike<'-1.1'>;
|
||||
//=> true
|
||||
|
||||
type C = IsNumberLike<1>;
|
||||
//=> true
|
||||
|
||||
type D = IsNumberLike<'a'>;
|
||||
//=> false
|
||||
*/
|
||||
export type IsNumberLike<N> =
|
||||
N extends number ? true
|
||||
: N extends `${number}`
|
||||
? true
|
||||
: N extends `${number}.${number}`
|
||||
? true
|
||||
: false;
|
||||
|
||||
/**
|
||||
Returns the minimum number in the given union of numbers.
|
||||
|
||||
Note: Just supports numbers from 0 to 999.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = UnionMin<3 | 1 | 2>;
|
||||
//=> 1
|
||||
```
|
||||
*/
|
||||
export type UnionMin<N extends number> = InternalUnionMin<N>;
|
||||
|
||||
/**
|
||||
The actual implementation of `UnionMin`. It's private because it has some arguments that don't need to be exposed.
|
||||
*/
|
||||
type InternalUnionMin<N extends number, T extends UnknownArray = []> =
|
||||
T['length'] extends N
|
||||
? T['length']
|
||||
: InternalUnionMin<N, [...T, unknown]>;
|
||||
|
||||
/**
|
||||
Returns the maximum number in the given union of numbers.
|
||||
|
||||
Note: Just supports numbers from 0 to 999.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = UnionMax<1 | 3 | 2>;
|
||||
//=> 3
|
||||
```
|
||||
*/
|
||||
export type UnionMax<N extends number> = InternalUnionMax<N>;
|
||||
|
||||
/**
|
||||
The actual implementation of `UnionMax`. It's private because it has some arguments that don't need to be exposed.
|
||||
*/
|
||||
type InternalUnionMax<N extends number, T extends UnknownArray = []> =
|
||||
IsNever<N> extends true
|
||||
? T['length']
|
||||
: T['length'] extends N
|
||||
? InternalUnionMax<Exclude<N, T['length']>, T>
|
||||
: InternalUnionMax<N, [...T, unknown]>;
|
||||
|
||||
/**
|
||||
Returns the number with reversed sign.
|
||||
|
||||
@example
|
||||
```
|
||||
ReverseSign<-1>;
|
||||
//=> 1
|
||||
|
||||
ReverseSign<1>;
|
||||
//=> -1
|
||||
|
||||
ReverseSign<NegativeInfinity>
|
||||
//=> PositiveInfinity
|
||||
|
||||
ReverseSign<PositiveInfinity>
|
||||
//=> NegativeInfinity
|
||||
```
|
||||
*/
|
||||
export type ReverseSign<N extends number> =
|
||||
// Handle edge cases
|
||||
N extends 0 ? 0 : N extends PositiveInfinity ? NegativeInfinity : N extends NegativeInfinity ? PositiveInfinity :
|
||||
// Handle negative numbers
|
||||
`${N}` extends `-${infer P extends number}` ? P
|
||||
// Handle positive numbers
|
||||
: `-${N}` extends `${infer R extends number}` ? R : never;
|
236
node_modules/type-fest/source/internal/object.d.ts
generated
vendored
Normal file
236
node_modules/type-fest/source/internal/object.d.ts
generated
vendored
Normal file
@@ -0,0 +1,236 @@
|
||||
import type {Simplify} from '../simplify';
|
||||
import type {UnknownArray} from '../unknown-array';
|
||||
import type {IsEqual} from '../is-equal';
|
||||
import type {KeysOfUnion} from '../keys-of-union';
|
||||
import type {RequiredKeysOf} from '../required-keys-of';
|
||||
import type {Merge} from '../merge';
|
||||
import type {IfAny} from '../if-any';
|
||||
import type {IfNever} from '../if-never';
|
||||
import type {OptionalKeysOf} from '../optional-keys-of';
|
||||
import type {FilterDefinedKeys, FilterOptionalKeys} from './keys';
|
||||
import type {NonRecursiveType} from './type';
|
||||
import type {ToString} from './string';
|
||||
|
||||
/**
|
||||
Create an object type with the given key `<Key>` and value `<Value>`.
|
||||
|
||||
It will copy the prefix and optional status of the same key from the given object `CopiedFrom` into the result.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = BuildObject<'a', string>;
|
||||
//=> {a: string}
|
||||
|
||||
// Copy `readonly` and `?` from the key `a` of `{readonly a?: any}`
|
||||
type B = BuildObject<'a', string, {readonly a?: any}>;
|
||||
//=> {readonly a?: string}
|
||||
```
|
||||
*/
|
||||
export type BuildObject<Key extends PropertyKey, Value, CopiedFrom extends object = {}> =
|
||||
Key extends keyof CopiedFrom
|
||||
? Pick<{[_ in keyof CopiedFrom]: Value}, Key>
|
||||
: Key extends `${infer NumberKey extends number}`
|
||||
? NumberKey extends keyof CopiedFrom
|
||||
? Pick<{[_ in keyof CopiedFrom]: Value}, NumberKey>
|
||||
: {[_ in Key]: Value}
|
||||
: {[_ in Key]: Value};
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a plain key-value object.
|
||||
*/
|
||||
export type IsPlainObject<T> =
|
||||
T extends NonRecursiveType | UnknownArray | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
|
||||
? false
|
||||
: T extends object
|
||||
? true
|
||||
: false;
|
||||
|
||||
/**
|
||||
Extract the object field type if T is an object and K is a key of T, return `never` otherwise.
|
||||
|
||||
It creates a type-safe way to access the member type of `unknown` type.
|
||||
*/
|
||||
export type ObjectValue<T, K> =
|
||||
K extends keyof T
|
||||
? T[K]
|
||||
: ToString<K> extends keyof T
|
||||
? T[ToString<K>]
|
||||
: K extends `${infer NumberK extends number}`
|
||||
? NumberK extends keyof T
|
||||
? T[NumberK]
|
||||
: never
|
||||
: never;
|
||||
|
||||
/**
|
||||
For an object T, if it has any properties that are a union with `undefined`, make those into optional properties instead.
|
||||
|
||||
@example
|
||||
```
|
||||
type User = {
|
||||
firstName: string;
|
||||
lastName: string | undefined;
|
||||
};
|
||||
|
||||
type OptionalizedUser = UndefinedToOptional<User>;
|
||||
//=> {
|
||||
// firstName: string;
|
||||
// lastName?: string;
|
||||
// }
|
||||
```
|
||||
*/
|
||||
export type UndefinedToOptional<T extends object> = Simplify<
|
||||
{
|
||||
// Property is not a union with `undefined`, keep it as-is.
|
||||
[Key in keyof Pick<T, FilterDefinedKeys<T>>]: T[Key];
|
||||
} & {
|
||||
// Property _is_ a union with defined value. Set as optional (via `?`) and remove `undefined` from the union.
|
||||
[Key in keyof Pick<T, FilterOptionalKeys<T>>]?: Exclude<T[Key], undefined>;
|
||||
}
|
||||
>;
|
||||
|
||||
/**
|
||||
Works similar to the built-in `Pick` utility type, except for the following differences:
|
||||
- Distributes over union types and allows picking keys from any member of the union type.
|
||||
- Primitives types are returned as-is.
|
||||
- Picks all keys if `Keys` is `any`.
|
||||
- Doesn't pick `number` from a `string` index signature.
|
||||
|
||||
@example
|
||||
```
|
||||
type ImageUpload = {
|
||||
url: string;
|
||||
size: number;
|
||||
thumbnailUrl: string;
|
||||
};
|
||||
|
||||
type VideoUpload = {
|
||||
url: string;
|
||||
duration: number;
|
||||
encodingFormat: string;
|
||||
};
|
||||
|
||||
// Distributes over union types and allows picking keys from any member of the union type
|
||||
type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
|
||||
//=> {url: string; size: number} | {url: string; duration: number}
|
||||
|
||||
// Primitive types are returned as-is
|
||||
type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
|
||||
//=> string | number
|
||||
|
||||
// Picks all keys if `Keys` is `any`
|
||||
type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
||||
//=> {a: 1; b: 2} | {c: 3}
|
||||
|
||||
// Doesn't pick `number` from a `string` index signature
|
||||
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
||||
//=> {}
|
||||
*/
|
||||
export type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {
|
||||
[P in keyof T as Extract<P, Keys>]: T[P]
|
||||
};
|
||||
|
||||
/**
|
||||
Extract all possible values for a given key from a union of object types.
|
||||
|
||||
@example
|
||||
```
|
||||
type Statuses = ValueOfUnion<{ id: 1, status: "open" } | { id: 2, status: "closed" }, "status">;
|
||||
//=> "open" | "closed"
|
||||
```
|
||||
*/
|
||||
export type ValueOfUnion<Union, Key extends KeysOfUnion<Union>> =
|
||||
Union extends unknown ? Key extends keyof Union ? Union[Key] : never : never;
|
||||
|
||||
/**
|
||||
Extract all readonly keys from a union of object types.
|
||||
|
||||
@example
|
||||
```
|
||||
type User = {
|
||||
readonly id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type Post = {
|
||||
readonly id: string;
|
||||
readonly author: string;
|
||||
body: string;
|
||||
};
|
||||
|
||||
type ReadonlyKeys = ReadonlyKeysOfUnion<User | Post>;
|
||||
//=> "id" | "author"
|
||||
```
|
||||
*/
|
||||
export type ReadonlyKeysOfUnion<Union> = Union extends unknown ? keyof {
|
||||
[Key in keyof Union as IsEqual<{[K in Key]: Union[Key]}, {readonly [K in Key]: Union[Key]}> extends true ? Key : never]: never
|
||||
} : never;
|
||||
|
||||
/**
|
||||
Merges user specified options with default options.
|
||||
|
||||
@example
|
||||
```
|
||||
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
||||
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
||||
type SpecifiedOptions = {leavesOnly: true};
|
||||
|
||||
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
||||
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
// Complains if default values are not provided for optional options
|
||||
|
||||
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
||||
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
||||
type SpecifiedOptions = {};
|
||||
|
||||
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
// Complains if an option's default type does not conform to the expected type
|
||||
|
||||
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
||||
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
||||
type SpecifiedOptions = {};
|
||||
|
||||
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
// Complains if an option's specified type does not conform to the expected type
|
||||
|
||||
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
||||
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
||||
type SpecifiedOptions = {leavesOnly: 'yes'};
|
||||
|
||||
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
||||
```
|
||||
*/
|
||||
export type ApplyDefaultOptions<
|
||||
Options extends object,
|
||||
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
||||
SpecifiedOptions extends Options,
|
||||
> =
|
||||
IfAny<SpecifiedOptions, Defaults,
|
||||
IfNever<SpecifiedOptions, Defaults,
|
||||
Simplify<Merge<Defaults, {
|
||||
[Key in keyof SpecifiedOptions
|
||||
as Key extends OptionalKeysOf<Options>
|
||||
? Extract<SpecifiedOptions[Key], undefined> extends never
|
||||
? Key
|
||||
: never
|
||||
: Key
|
||||
]: SpecifiedOptions[Key]
|
||||
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
||||
>>;
|
210
node_modules/type-fest/source/internal/string.d.ts
generated
vendored
Normal file
210
node_modules/type-fest/source/internal/string.d.ts
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
import type {NegativeInfinity, PositiveInfinity} from '../numeric';
|
||||
import type {Trim} from '../trim';
|
||||
import type {Whitespace} from './characters';
|
||||
import type {BuildTuple} from './tuple';
|
||||
|
||||
/**
|
||||
Return a string representation of the given string or number.
|
||||
|
||||
Note: This type is not the return type of the `.toString()` function.
|
||||
*/
|
||||
export type ToString<T> = T extends string | number ? `${T}` : never;
|
||||
|
||||
/**
|
||||
Converts a numeric string to a number.
|
||||
|
||||
@example
|
||||
```
|
||||
type PositiveInt = StringToNumber<'1234'>;
|
||||
//=> 1234
|
||||
|
||||
type NegativeInt = StringToNumber<'-1234'>;
|
||||
//=> -1234
|
||||
|
||||
type PositiveFloat = StringToNumber<'1234.56'>;
|
||||
//=> 1234.56
|
||||
|
||||
type NegativeFloat = StringToNumber<'-1234.56'>;
|
||||
//=> -1234.56
|
||||
|
||||
type PositiveInfinity = StringToNumber<'Infinity'>;
|
||||
//=> Infinity
|
||||
|
||||
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
||||
//=> -Infinity
|
||||
```
|
||||
|
||||
@category String
|
||||
@category Numeric
|
||||
@category Template literal
|
||||
*/
|
||||
export type StringToNumber<S extends string> = S extends `${infer N extends number}`
|
||||
? N
|
||||
: S extends 'Infinity'
|
||||
? PositiveInfinity
|
||||
: S extends '-Infinity'
|
||||
? NegativeInfinity
|
||||
: never;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given string `S` starts with the given string `SearchString`.
|
||||
|
||||
@example
|
||||
```
|
||||
StartsWith<'abcde', 'abc'>;
|
||||
//=> true
|
||||
|
||||
StartsWith<'abcde', 'bc'>;
|
||||
//=> false
|
||||
|
||||
StartsWith<string, 'bc'>;
|
||||
//=> never
|
||||
|
||||
StartsWith<'abcde', string>;
|
||||
//=> never
|
||||
```
|
||||
|
||||
@category String
|
||||
@category Template literal
|
||||
*/
|
||||
export type StartsWith<S extends string, SearchString extends string> = string extends S | SearchString
|
||||
? never
|
||||
: S extends `${SearchString}${infer T}`
|
||||
? true
|
||||
: false;
|
||||
|
||||
/**
|
||||
Returns an array of the characters of the string.
|
||||
|
||||
@example
|
||||
```
|
||||
StringToArray<'abcde'>;
|
||||
//=> ['a', 'b', 'c', 'd', 'e']
|
||||
|
||||
StringToArray<string>;
|
||||
//=> never
|
||||
```
|
||||
|
||||
@category String
|
||||
*/
|
||||
export type StringToArray<S extends string, Result extends string[] = []> = string extends S
|
||||
? never
|
||||
: S extends `${infer F}${infer R}`
|
||||
? StringToArray<R, [...Result, F]>
|
||||
: Result;
|
||||
|
||||
/**
|
||||
Returns the length of the given string.
|
||||
|
||||
@example
|
||||
```
|
||||
StringLength<'abcde'>;
|
||||
//=> 5
|
||||
|
||||
StringLength<string>;
|
||||
//=> never
|
||||
```
|
||||
|
||||
@category String
|
||||
@category Template literal
|
||||
*/
|
||||
export type StringLength<S extends string> = string extends S
|
||||
? never
|
||||
: StringToArray<S>['length'];
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the string is lowercased.
|
||||
*/
|
||||
export type IsLowerCase<T extends string> = T extends Lowercase<T> ? true : false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the string is uppercased.
|
||||
*/
|
||||
export type IsUpperCase<T extends string> = T extends Uppercase<T> ? true : false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether a string is whitespace.
|
||||
*/
|
||||
export type IsWhitespace<T extends string> = T extends Whitespace
|
||||
? true
|
||||
: T extends `${Whitespace}${infer Rest}`
|
||||
? IsWhitespace<Rest>
|
||||
: false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the string is numeric.
|
||||
|
||||
This type is a workaround for [Microsoft/TypeScript#46109](https://github.com/microsoft/TypeScript/issues/46109#issuecomment-930307987).
|
||||
*/
|
||||
export type IsNumeric<T extends string> = T extends `${number}`
|
||||
? Trim<T> extends T
|
||||
? true
|
||||
: false
|
||||
: false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
|
||||
|
||||
@example
|
||||
```
|
||||
SameLengthPositiveNumericStringGt<'50', '10'>;
|
||||
//=> true
|
||||
|
||||
SameLengthPositiveNumericStringGt<'10', '10'>;
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}`
|
||||
? B extends `${infer FirstB}${infer RestB}`
|
||||
? FirstA extends FirstB
|
||||
? SameLengthPositiveNumericStringGt<RestA, RestB>
|
||||
: PositiveNumericCharacterGt<FirstA, FirstB>
|
||||
: never
|
||||
: false;
|
||||
|
||||
type NumericString = '0123456789';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
|
||||
|
||||
@example
|
||||
```
|
||||
PositiveNumericStringGt<'500', '1'>;
|
||||
//=> true
|
||||
|
||||
PositiveNumericStringGt<'1', '1'>;
|
||||
//=> false
|
||||
|
||||
PositiveNumericStringGt<'1', '500'>;
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
export type PositiveNumericStringGt<A extends string, B extends string> = A extends B
|
||||
? false
|
||||
: [BuildTuple<StringLength<A>, 0>, BuildTuple<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]]
|
||||
? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
|
||||
? 0 extends Remain['length']
|
||||
? SameLengthPositiveNumericStringGt<A, B>
|
||||
: true
|
||||
: false
|
||||
: never;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
|
||||
|
||||
@example
|
||||
```
|
||||
PositiveNumericCharacterGt<'5', '1'>;
|
||||
//=> true
|
||||
|
||||
PositiveNumericCharacterGt<'1', '1'>;
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}`
|
||||
? NumericString extends `${infer HeadB}${B}${infer TailB}`
|
||||
? HeadA extends `${HeadB}${infer _}${infer __}`
|
||||
? true
|
||||
: false
|
||||
: never
|
||||
: never;
|
90
node_modules/type-fest/source/internal/tuple.d.ts
generated
vendored
Normal file
90
node_modules/type-fest/source/internal/tuple.d.ts
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import type {GreaterThan} from '../greater-than';
|
||||
import type {LessThan} from '../less-than';
|
||||
import type {NegativeInfinity, PositiveInfinity} from '../numeric';
|
||||
import type {UnknownArray} from '../unknown-array';
|
||||
|
||||
/**
|
||||
Infer the length of the given tuple `<T>`.
|
||||
|
||||
Returns `never` if the given type is an non-fixed-length array like `Array<string>`.
|
||||
|
||||
@example
|
||||
```
|
||||
type Tuple = TupleLength<[string, number, boolean]>;
|
||||
//=> 3
|
||||
|
||||
type Array = TupleLength<string[]>;
|
||||
//=> never
|
||||
|
||||
// Supports union types.
|
||||
type Union = TupleLength<[] | [1, 2, 3] | Array<number>>;
|
||||
//=> 1 | 3
|
||||
```
|
||||
*/
|
||||
export type TupleLength<T extends UnknownArray> =
|
||||
// `extends unknown` is used to convert `T` (if `T` is a union type) to
|
||||
// a [distributive conditionaltype](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types))
|
||||
T extends unknown
|
||||
? number extends T['length']
|
||||
? never // Return never if the given type is an non-flexed-length array like `Array<string>`
|
||||
: T['length']
|
||||
: never; // Should never happen
|
||||
|
||||
/**
|
||||
Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
|
||||
|
||||
If `<Fill>` is not provided, it will default to `unknown`.
|
||||
|
||||
@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
|
||||
*/
|
||||
export type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = []> = number extends L
|
||||
? Fill[]
|
||||
: L extends T['length']
|
||||
? T
|
||||
: BuildTuple<L, Fill, [...T, Fill]>;
|
||||
|
||||
/**
|
||||
Returns the maximum value from a tuple of integers.
|
||||
|
||||
Note:
|
||||
- Float numbers are not supported.
|
||||
|
||||
@example
|
||||
```
|
||||
ArrayMax<[1, 2, 5, 3]>;
|
||||
//=> 5
|
||||
|
||||
ArrayMax<[1, 2, 5, 3, 99, -1]>;
|
||||
//=> 99
|
||||
```
|
||||
*/
|
||||
export type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number]
|
||||
? never :
|
||||
A extends [infer F extends number, ...infer R extends number[]]
|
||||
? GreaterThan<F, Result> extends true
|
||||
? TupleMax<R, F>
|
||||
: TupleMax<R, Result>
|
||||
: Result;
|
||||
|
||||
/**
|
||||
Returns the minimum value from a tuple of integers.
|
||||
|
||||
Note:
|
||||
- Float numbers are not supported.
|
||||
|
||||
@example
|
||||
```
|
||||
ArrayMin<[1, 2, 5, 3]>;
|
||||
//=> 1
|
||||
|
||||
ArrayMin<[1, 2, 5, 3, -5]>;
|
||||
//=> -5
|
||||
```
|
||||
*/
|
||||
export type TupleMin<A extends number[], Result extends number = PositiveInfinity> = number extends A[number]
|
||||
? never
|
||||
: A extends [infer F extends number, ...infer R extends number[]]
|
||||
? LessThan<F, Result> extends true
|
||||
? TupleMin<R, F>
|
||||
: TupleMin<R, Result>
|
||||
: Result;
|
139
node_modules/type-fest/source/internal/type.d.ts
generated
vendored
Normal file
139
node_modules/type-fest/source/internal/type.d.ts
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
import type {IsAny} from '../is-any';
|
||||
import type {IsNever} from '../is-never';
|
||||
import type {Primitive} from '../primitive';
|
||||
|
||||
/**
|
||||
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
||||
*/
|
||||
export type BuiltIns = Primitive | void | Date | RegExp;
|
||||
|
||||
/**
|
||||
Matches non-recursive types.
|
||||
*/
|
||||
export type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the two given types extends the base type.
|
||||
*/
|
||||
export type IsBothExtends<BaseType, FirstType, SecondType> = FirstType extends BaseType
|
||||
? SecondType extends BaseType
|
||||
? true
|
||||
: false
|
||||
: false;
|
||||
|
||||
/**
|
||||
Test if the given function has multiple call signatures.
|
||||
|
||||
Needed to handle the case of a single call signature with properties.
|
||||
|
||||
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
||||
@see https://github.com/microsoft/TypeScript/issues/29732
|
||||
*/
|
||||
export type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
||||
T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
|
||||
? B extends A
|
||||
? A extends B
|
||||
? false
|
||||
: true
|
||||
: true
|
||||
: false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given `boolean` is not `false`.
|
||||
*/
|
||||
export type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is primitive value or primitive type.
|
||||
|
||||
@example
|
||||
```
|
||||
IsPrimitive<'string'>
|
||||
//=> true
|
||||
|
||||
IsPrimitive<string>
|
||||
//=> true
|
||||
|
||||
IsPrimitive<Object>
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether A is false.
|
||||
|
||||
@example
|
||||
```
|
||||
Not<true>;
|
||||
//=> false
|
||||
|
||||
Not<false>;
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
export type Not<A extends boolean> = A extends true
|
||||
? false
|
||||
: A extends false
|
||||
? true
|
||||
: never;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a union type.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = IsUnion<string | number>;
|
||||
//=> true
|
||||
|
||||
type B = IsUnion<string>;
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
export type IsUnion<T> = InternalIsUnion<T>;
|
||||
|
||||
/**
|
||||
The actual implementation of `IsUnion`.
|
||||
*/
|
||||
type InternalIsUnion<T, U = T> =
|
||||
(
|
||||
// @link https://ghaiklor.github.io/type-challenges-solutions/en/medium-isunion.html
|
||||
IsNever<T> extends true
|
||||
? false
|
||||
: T extends any
|
||||
? [U] extends [T]
|
||||
? false
|
||||
: true
|
||||
: never
|
||||
) extends infer Result
|
||||
// In some cases `Result` will return `false | true` which is `boolean`,
|
||||
// that means `T` has at least two types and it's a union type,
|
||||
// so we will return `true` instead of `boolean`.
|
||||
? boolean extends Result ? true
|
||||
: Result
|
||||
: never; // Should never happen
|
||||
|
||||
/**
|
||||
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
||||
|
||||
@example
|
||||
```
|
||||
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
||||
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
||||
//=> 'VALID'
|
||||
|
||||
// When `T` is `any` => Returns `IfAny` branch
|
||||
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
||||
//=> 'IS_ANY'
|
||||
|
||||
// When `T` is `never` => Returns `IfNever` branch
|
||||
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
||||
//=> 'IS_NEVER'
|
||||
```
|
||||
*/
|
||||
export type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> =
|
||||
IsAny<T> extends true
|
||||
? IfAny
|
||||
: IsNever<T> extends true
|
||||
? IfNever
|
||||
: IfNotAnyOrNever;
|
76
node_modules/type-fest/source/invariant-of.d.ts
generated
vendored
Normal file
76
node_modules/type-fest/source/invariant-of.d.ts
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
declare const invariantBrand: unique symbol;
|
||||
|
||||
/**
|
||||
Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
|
||||
|
||||
Use-case:
|
||||
- Prevent runtime errors that may occur due to assigning subtypes to supertypes.
|
||||
- Improve type signature of object methods like [`Object.keys()` or `Object.entries()`](https://github.com/microsoft/TypeScript/pull/12253#issuecomment-263132208) by sealing the object type.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {InvariantOf} from 'type-fest';
|
||||
|
||||
class Animal {
|
||||
constructor(public name: string){}
|
||||
}
|
||||
|
||||
class Cat extends Animal {
|
||||
meow() {}
|
||||
}
|
||||
|
||||
let animalArray: Animal[] = [animal];
|
||||
let catArray: Cat[] = [cat];
|
||||
|
||||
animalArray = catArray; // Okay if covariant
|
||||
animalArray.push(new Animal('another animal')); // Pushed an animal into catArray
|
||||
catArray.forEach(c => c.meow()); // Allowed but, error at runtime
|
||||
|
||||
let invariantAnimalArray: InvariantOf<Animal>[] = [animal] as InvariantOf<Animal>[];
|
||||
let invariantCatArray: InvariantOf<Cat>[] = [cat] as InvariantOf<Cat>[];
|
||||
|
||||
invariantAnimalArray = invariantCatArray; // Error: Type 'InvariantOf<Cat>[]' is not assignable to type 'InvariantOf<Animal>[]'.
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {InvariantOf} from 'type-fest';
|
||||
|
||||
// In covariance (default)
|
||||
|
||||
interface FooBar {
|
||||
foo: number;
|
||||
bar: string
|
||||
}
|
||||
|
||||
interface FooBarBaz extends FooBar {
|
||||
baz: boolean
|
||||
}
|
||||
|
||||
declare const fooBar: FooBar
|
||||
declare const fooBarBaz: FooBarBaz
|
||||
|
||||
function keyOfFooBar(fooBar: FooBar) {
|
||||
return Object.keys(fooBar) as (keyof FooBar)[]
|
||||
}
|
||||
|
||||
keyOfFooBar(fooBar) //=> (keyof FooBar)[]
|
||||
keyOfFooBar(fooBarBaz) //=> (keyof FooBar)[] but, (keyof FooBarBaz)[] at runtime
|
||||
|
||||
// In invariance
|
||||
|
||||
export function invariantOf<Type>(value: Type): InvariantOf<Type> {
|
||||
return value as InvariantOf<Type>;
|
||||
}
|
||||
|
||||
function keyOfInvariantFooBar(fooBar: InvariantOf<FooBar>) {
|
||||
return Object.keys(fooBar) as (keyof FooBar)[]
|
||||
}
|
||||
|
||||
keyOfInvariantFooBar(invariantOf(fooBar)); // (keyof FooBar)[]
|
||||
keyOfInvariantFooBar(invariantOf(fooBarBaz)); // Error: Argument of type 'InvariantOf<FooBarBaz>' is not assignable to parameter of type 'InvariantOf<FooBar>'.
|
||||
```
|
||||
|
||||
@category Type
|
||||
*/
|
||||
export type InvariantOf<Type> = Type & {[invariantBrand]: (_: Type) => Type};
|
33
node_modules/type-fest/source/is-any.d.ts
generated
vendored
Normal file
33
node_modules/type-fest/source/is-any.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// Can eventually be replaced with the built-in once this library supports
|
||||
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
||||
type NoInfer<T> = T extends infer U ? U : never;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is `any`.
|
||||
|
||||
@link https://stackoverflow.com/a/49928360/1490091
|
||||
|
||||
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsAny} from 'type-fest';
|
||||
|
||||
const typedObject = {a: 1, b: 2} as const;
|
||||
const anyObject: any = {a: 1, b: 2};
|
||||
|
||||
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
||||
return obj[key];
|
||||
}
|
||||
|
||||
const typedA = get(typedObject, 'a');
|
||||
//=> 1
|
||||
|
||||
const anyA = get(anyObject, 'a');
|
||||
//=> any
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
31
node_modules/type-fest/source/is-equal.d.ts
generated
vendored
Normal file
31
node_modules/type-fest/source/is-equal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
Returns a boolean for whether the two given types are equal.
|
||||
|
||||
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
||||
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
||||
|
||||
Use-cases:
|
||||
- If you want to make a conditional branch based on the result of a comparison of two types.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsEqual} from 'type-fest';
|
||||
|
||||
// This type returns a boolean for whether the given array includes the given item.
|
||||
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
||||
type Includes<Value extends readonly any[], Item> =
|
||||
Value extends readonly [Value[0], ...infer rest]
|
||||
? IsEqual<Value[0], Item> extends true
|
||||
? true
|
||||
: Includes<rest, Item>
|
||||
: false;
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsEqual<A, B> =
|
||||
(<G>() => G extends A & G | G ? 1 : 2) extends
|
||||
(<G>() => G extends B & G | G ? 1 : 2)
|
||||
? true
|
||||
: false;
|
41
node_modules/type-fest/source/is-float.d.ts
generated
vendored
Normal file
41
node_modules/type-fest/source/is-float.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
|
||||
|
||||
Use-case:
|
||||
- If you want to make a conditional branch based on the result of whether a number is a float or not.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsFloat, PositiveInfinity} from "type-fest";
|
||||
|
||||
type A = IsFloat<1.5>;
|
||||
//=> true
|
||||
|
||||
type B = IsFloat<-1.5>;
|
||||
//=> true
|
||||
|
||||
type C = IsFloat<1e-7>;
|
||||
//=> true
|
||||
|
||||
type D = IsFloat<1.0>;
|
||||
//=> false
|
||||
|
||||
type E = IsFloat<PositiveInfinity>;
|
||||
//=> false
|
||||
|
||||
type F = IsFloat<1.23e+21>;
|
||||
//=> false
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Numeric
|
||||
*/
|
||||
export type IsFloat<T> = T extends number
|
||||
? `${T}` extends `${number}e${infer E extends '-' | '+'}${number}`
|
||||
? E extends '-'
|
||||
? true
|
||||
: false
|
||||
: `${T}` extends `${number}.${number}`
|
||||
? true
|
||||
: false
|
||||
: false;
|
58
node_modules/type-fest/source/is-integer.d.ts
generated
vendored
Normal file
58
node_modules/type-fest/source/is-integer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import type {Not} from './internal';
|
||||
import type {IsFloat} from './is-float';
|
||||
import type {PositiveInfinity, NegativeInfinity} from './numeric';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given number is an integer, like `-5`, `1.0`, or `100`.
|
||||
|
||||
Use-case:
|
||||
- If you want to make a conditional branch based on the result of whether a number is an integer or not.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsInteger, PositiveInfinity} from "type-fest";
|
||||
|
||||
type A = IsInteger<1>;
|
||||
//=> true
|
||||
|
||||
type B = IsInteger<1.0>;
|
||||
//=> true
|
||||
|
||||
type C = IsInteger<-1>;
|
||||
//=> true
|
||||
|
||||
type D = IsInteger<0b10>;
|
||||
//=> true
|
||||
|
||||
type E = IsInteger<0o10>;
|
||||
//=> true
|
||||
|
||||
type F = IsInteger<0x10>;
|
||||
//=> true
|
||||
|
||||
type G = IsInteger<1.23+21>;
|
||||
//=> true
|
||||
|
||||
type H = IsInteger<1.5>;
|
||||
//=> false
|
||||
|
||||
type I = IsInteger<PositiveInfinity>;
|
||||
//=> false
|
||||
|
||||
type J = IsInteger<1e-7>;
|
||||
//=> false
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Numeric
|
||||
*/
|
||||
export type IsInteger<T> =
|
||||
T extends bigint
|
||||
? true
|
||||
: T extends number
|
||||
? number extends T
|
||||
? false
|
||||
: T extends PositiveInfinity | NegativeInfinity
|
||||
? false
|
||||
: Not<IsFloat<T>>
|
||||
: false;
|
296
node_modules/type-fest/source/is-literal.d.ts
generated
vendored
Normal file
296
node_modules/type-fest/source/is-literal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
import type {Primitive} from './primitive';
|
||||
import type {Numeric} from './numeric';
|
||||
import type {IsNotFalse, IsPrimitive} from './internal';
|
||||
import type {IsNever} from './is-never';
|
||||
import type {IfNever} from './if-never';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type `T` is the specified `LiteralType`.
|
||||
|
||||
@link https://stackoverflow.com/a/52806744/10292952
|
||||
|
||||
@example
|
||||
```
|
||||
LiteralCheck<1, number>
|
||||
//=> true
|
||||
|
||||
LiteralCheck<number, number>
|
||||
//=> false
|
||||
|
||||
LiteralCheck<1, string>
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
type LiteralCheck<T, LiteralType extends Primitive> = (
|
||||
IsNever<T> extends false // Must be wider than `never`
|
||||
? [T] extends [LiteralType & infer U] // Remove any branding
|
||||
? [U] extends [LiteralType] // Must be narrower than `LiteralType`
|
||||
? [LiteralType] extends [U] // Cannot be wider than `LiteralType`
|
||||
? false
|
||||
: true
|
||||
: false
|
||||
: false
|
||||
: false
|
||||
);
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type `T` is one of the specified literal types in `LiteralUnionType`.
|
||||
|
||||
@example
|
||||
```
|
||||
LiteralChecks<1, Numeric>
|
||||
//=> true
|
||||
|
||||
LiteralChecks<1n, Numeric>
|
||||
//=> true
|
||||
|
||||
LiteralChecks<bigint, Numeric>
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
type LiteralChecks<T, LiteralUnionType> = (
|
||||
// Conditional type to force union distribution.
|
||||
// If `T` is none of the literal types in the union `LiteralUnionType`, then `LiteralCheck<T, LiteralType>` will evaluate to `false` for the whole union.
|
||||
// If `T` is one of the literal types in the union, it will evaluate to `boolean` (i.e. `true | false`)
|
||||
IsNotFalse<LiteralUnionType extends Primitive
|
||||
? LiteralCheck<T, LiteralUnionType>
|
||||
: never
|
||||
>
|
||||
);
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
||||
|
||||
Useful for:
|
||||
- providing strongly-typed string manipulation functions
|
||||
- constraining strings to be a string literal
|
||||
- type utilities, such as when constructing parsers and ASTs
|
||||
|
||||
The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsStringLiteral} from 'type-fest';
|
||||
|
||||
type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
|
||||
|
||||
// https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
|
||||
function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
|
||||
return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
|
||||
}
|
||||
|
||||
const output = capitalize('hello, world!');
|
||||
//=> 'Hello, world!'
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
// String types with infinite set of possible values return `false`.
|
||||
|
||||
import type {IsStringLiteral} from 'type-fest';
|
||||
|
||||
type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
|
||||
//=> false
|
||||
|
||||
type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
|
||||
//=> false
|
||||
|
||||
// This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
|
||||
|
||||
type Length<S extends string, Counter extends never[] = []> =
|
||||
IsStringLiteral<S> extends false
|
||||
? number // return `number` for infinite string types
|
||||
: S extends `${string}${infer Tail}`
|
||||
? Length<Tail, [...Counter, never]>
|
||||
: Counter['length'];
|
||||
|
||||
type L1 = Length<Lowercase<string>>;
|
||||
//=> number
|
||||
|
||||
type L2 = Length<`${number}`>;
|
||||
//=> number
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsStringLiteral<T> = IfNever<T, false,
|
||||
// If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
|
||||
// and since `{}` extends index signatures, the result becomes `false`.
|
||||
T extends string
|
||||
? {} extends Record<T, never>
|
||||
? false
|
||||
: true
|
||||
: false>;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
||||
|
||||
Useful for:
|
||||
- providing strongly-typed functions when given literal arguments
|
||||
- type utilities, such as when constructing parsers and ASTs
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsNumericLiteral} from 'type-fest';
|
||||
|
||||
// https://github.com/inocan-group/inferred-types/blob/master/src/types/boolean-logic/EndsWith.ts
|
||||
type EndsWith<TValue, TEndsWith extends string> =
|
||||
TValue extends string
|
||||
? IsStringLiteral<TEndsWith> extends true
|
||||
? IsStringLiteral<TValue> extends true
|
||||
? TValue extends `${string}${TEndsWith}`
|
||||
? true
|
||||
: false
|
||||
: boolean
|
||||
: boolean
|
||||
: TValue extends number
|
||||
? IsNumericLiteral<TValue> extends true
|
||||
? EndsWith<`${TValue}`, TEndsWith>
|
||||
: false
|
||||
: false;
|
||||
|
||||
function endsWith<Input extends string | number, End extends string>(input: Input, end: End) {
|
||||
return `${input}`.endsWith(end) as EndsWith<Input, End>;
|
||||
}
|
||||
|
||||
endsWith('abc', 'c');
|
||||
//=> true
|
||||
|
||||
endsWith(123456, '456');
|
||||
//=> true
|
||||
|
||||
const end = '123' as string;
|
||||
|
||||
endsWith('abc123', end);
|
||||
//=> boolean
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a `true` or `false` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
||||
|
||||
Useful for:
|
||||
- providing strongly-typed functions when given literal arguments
|
||||
- type utilities, such as when constructing parsers and ASTs
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsBooleanLiteral} from 'type-fest';
|
||||
|
||||
const id = 123;
|
||||
|
||||
type GetId<AsString extends boolean> =
|
||||
IsBooleanLiteral<AsString> extends true
|
||||
? AsString extends true
|
||||
? `${typeof id}`
|
||||
: typeof id
|
||||
: number | string;
|
||||
|
||||
function getId<AsString extends boolean = false>(options?: {asString: AsString}) {
|
||||
return (options?.asString ? `${id}` : id) as GetId<AsString>;
|
||||
}
|
||||
|
||||
const numberId = getId();
|
||||
//=> 123
|
||||
|
||||
const stringId = getId({asString: true});
|
||||
//=> '123'
|
||||
|
||||
declare const runtimeBoolean: boolean;
|
||||
const eitherId = getId({asString: runtimeBoolean});
|
||||
//=> number | string
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsBooleanLiteral<T> = LiteralCheck<T, boolean>;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a `symbol` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
||||
|
||||
Useful for:
|
||||
- providing strongly-typed functions when given literal arguments
|
||||
- type utilities, such as when constructing parsers and ASTs
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsSymbolLiteral} from 'type-fest';
|
||||
|
||||
type Get<Obj extends Record<symbol, number>, Key extends keyof Obj> =
|
||||
IsSymbolLiteral<Key> extends true
|
||||
? Obj[Key]
|
||||
: number;
|
||||
|
||||
function get<Obj extends Record<symbol, number>, Key extends keyof Obj>(o: Obj, key: Key) {
|
||||
return o[key] as Get<Obj, Key>;
|
||||
}
|
||||
|
||||
const symbolLiteral = Symbol('literal');
|
||||
const symbolValue: symbol = Symbol('value');
|
||||
|
||||
get({[symbolLiteral]: 1} as const, symbolLiteral);
|
||||
//=> 1
|
||||
|
||||
get({[symbolValue]: 1} as const, symbolValue);
|
||||
//=> number
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsSymbolLiteral<T> = LiteralCheck<T, symbol>;
|
||||
|
||||
/** Helper type for `IsLiteral`. */
|
||||
type IsLiteralUnion<T> =
|
||||
| IsStringLiteral<T>
|
||||
| IsNumericLiteral<T>
|
||||
| IsBooleanLiteral<T>
|
||||
| IsSymbolLiteral<T>;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
||||
|
||||
Useful for:
|
||||
- providing strongly-typed functions when given literal arguments
|
||||
- type utilities, such as when constructing parsers and ASTs
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsLiteral} from 'type-fest';
|
||||
|
||||
// https://github.com/inocan-group/inferred-types/blob/master/src/types/string-literals/StripLeading.ts
|
||||
export type StripLeading<A, B> =
|
||||
A extends string
|
||||
? B extends string
|
||||
? IsLiteral<A> extends true
|
||||
? string extends B ? never : A extends `${B & string}${infer After}` ? After : A
|
||||
: string
|
||||
: A
|
||||
: A;
|
||||
|
||||
function stripLeading<Input extends string, Strip extends string>(input: Input, strip: Strip) {
|
||||
return input.replace(`^${strip}`, '') as StripLeading<Input, Strip>;
|
||||
}
|
||||
|
||||
stripLeading('abc123', 'abc');
|
||||
//=> '123'
|
||||
|
||||
const str = 'abc123' as string;
|
||||
|
||||
stripLeading(str, 'abc');
|
||||
//=> string
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsLiteral<T> =
|
||||
IsPrimitive<T> extends true
|
||||
? IsNotFalse<IsLiteralUnion<T>>
|
||||
: false;
|
42
node_modules/type-fest/source/is-never.d.ts
generated
vendored
Normal file
42
node_modules/type-fest/source/is-never.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
Returns a boolean for whether the given type is `never`.
|
||||
|
||||
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
||||
@link https://stackoverflow.com/a/53984913/10292952
|
||||
@link https://www.zhenghao.io/posts/ts-never
|
||||
|
||||
Useful in type utilities, such as checking if something does not occur.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsNever, And} from 'type-fest';
|
||||
|
||||
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
||||
type AreStringsEqual<A extends string, B extends string> =
|
||||
And<
|
||||
IsNever<Exclude<A, B>> extends true ? true : false,
|
||||
IsNever<Exclude<B, A>> extends true ? true : false
|
||||
>;
|
||||
|
||||
type EndIfEqual<I extends string, O extends string> =
|
||||
AreStringsEqual<I, O> extends true
|
||||
? never
|
||||
: void;
|
||||
|
||||
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
||||
if (input === output) {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
endIfEqual('abc', 'abc');
|
||||
//=> never
|
||||
|
||||
endIfEqual('abc', '123');
|
||||
//=> void
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsNever<T> = [T] extends [never] ? true : false;
|
20
node_modules/type-fest/source/is-null.d.ts
generated
vendored
Normal file
20
node_modules/type-fest/source/is-null.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
Returns a boolean for whether the given type is `null`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsNull} from 'type-fest';
|
||||
|
||||
type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
|
||||
|
||||
type Example1 = NonNullFallback<null, string>;
|
||||
//=> string
|
||||
|
||||
type Example2 = NonNullFallback<number, string>;
|
||||
//=? number
|
||||
```
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsNull<T> = [T] extends [null] ? true : false;
|
89
node_modules/type-fest/source/is-tuple.d.ts
generated
vendored
Normal file
89
node_modules/type-fest/source/is-tuple.d.ts
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import type {IfAny} from './if-any';
|
||||
import type {IfNever} from './if-never';
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
/**
|
||||
@see {@link IsTuple}
|
||||
*/
|
||||
export type IsTupleOptions = {
|
||||
/**
|
||||
Consider only fixed length arrays as tuples.
|
||||
|
||||
- When set to `true` (default), arrays with rest elements (e.g., `[1, ...number[]]`) are _not_ considered as tuples.
|
||||
- When set to `false`, arrays with at least one non-rest element (e.g., `[1, ...number[]]`) are considered as tuples.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```ts
|
||||
import type {IsTuple} from 'type-fest';
|
||||
|
||||
type Example1 = IsTuple<[number, ...number[]], {fixedLengthOnly: true}>;
|
||||
//=> false
|
||||
|
||||
type Example2 = IsTuple<[number, ...number[]], {fixedLengthOnly: false}>;
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
fixedLengthOnly?: boolean;
|
||||
};
|
||||
|
||||
type DefaultIsTupleOptions = {
|
||||
fixedLengthOnly: true;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given array is a tuple.
|
||||
|
||||
Use-case:
|
||||
- If you want to make a conditional branch based on the result of whether an array is a tuple or not.
|
||||
|
||||
Note: `IsTuple` returns `boolean` when instantiated with a union of tuple and non-tuple (e.g., `IsTuple<[1, 2] | number[]>`).
|
||||
|
||||
@example
|
||||
```ts
|
||||
import type {IsTuple} from 'type-fest';
|
||||
|
||||
type Tuple = IsTuple<[1, 2, 3]>;
|
||||
//=> true
|
||||
|
||||
type NotTuple = IsTuple<number[]>;
|
||||
//=> false
|
||||
|
||||
type TupleWithOptionalItems = IsTuple<[1?, 2?]>;
|
||||
//=> true
|
||||
|
||||
type RestItemsNotAllowed = IsTuple<[1, 2, ...number[]]>;
|
||||
//=> false
|
||||
|
||||
type RestItemsAllowed = IsTuple<[1, 2, ...number[]], {fixedLengthOnly: false}>;
|
||||
//=> true
|
||||
```
|
||||
|
||||
@see {@link IsTupleOptions}
|
||||
|
||||
@category Type Guard
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsTuple<
|
||||
TArray extends UnknownArray,
|
||||
Options extends IsTupleOptions = {},
|
||||
> =
|
||||
_IsTuple<TArray, ApplyDefaultOptions<IsTupleOptions, DefaultIsTupleOptions, Options>>;
|
||||
|
||||
type _IsTuple<
|
||||
TArray extends UnknownArray,
|
||||
Options extends Required<IsTupleOptions>,
|
||||
> =
|
||||
IfAny<TArray, boolean, IfNever<TArray, false,
|
||||
TArray extends unknown // For distributing `TArray`
|
||||
? number extends TArray['length']
|
||||
? Options['fixedLengthOnly'] extends false
|
||||
? IfNever<keyof TArray & `${number}`,
|
||||
TArray extends readonly [...any, any] ? true : false, // To handle cases where a non-rest element follows a rest element, e.g., `[...number[], number]`
|
||||
true>
|
||||
: false
|
||||
: true
|
||||
: false
|
||||
>>;
|
52
node_modules/type-fest/source/is-unknown.d.ts
generated
vendored
Normal file
52
node_modules/type-fest/source/is-unknown.d.ts
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import type {IsNull} from './is-null';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given type is `unknown`.
|
||||
|
||||
@link https://github.com/dsherret/conditional-type-checks/pull/16
|
||||
|
||||
Useful in type utilities, such as when dealing with unknown data from API calls.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsUnknown} from 'type-fest';
|
||||
|
||||
// https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
|
||||
type Action<TState, TPayload = void> =
|
||||
IsUnknown<TPayload> extends true
|
||||
? (state: TState) => TState,
|
||||
: (state: TState, payload: TPayload) => TState;
|
||||
|
||||
class Store<TState> {
|
||||
constructor(private state: TState) {}
|
||||
|
||||
execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
|
||||
this.state = action(this.state, payload);
|
||||
return this.state;
|
||||
}
|
||||
|
||||
// ... other methods
|
||||
}
|
||||
|
||||
const store = new Store({value: 1});
|
||||
declare const someExternalData: unknown;
|
||||
|
||||
store.execute(state => ({value: state.value + 1}));
|
||||
//=> `TPayload` is `void`
|
||||
|
||||
store.execute((state, payload) => ({value: state.value + payload}), 5);
|
||||
//=> `TPayload` is `5`
|
||||
|
||||
store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
|
||||
//=> Errors: `action` is `(state: TState) => TState`
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type IsUnknown<T> = (
|
||||
unknown extends T // `T` can be `unknown` or `any`
|
||||
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
|
||||
? true
|
||||
: false
|
||||
: false
|
||||
);
|
64
node_modules/type-fest/source/iterable-element.d.ts
generated
vendored
Normal file
64
node_modules/type-fest/source/iterable-element.d.ts
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
Get the element type of an `Iterable`/`AsyncIterable`. For example, `Array`, `Set`, `Map`, generator, stream, etc.
|
||||
|
||||
This can be useful, for example, if you want to get the type that is yielded in a generator function. Often the return type of those functions are not specified.
|
||||
|
||||
This type works with both `Iterable`s and `AsyncIterable`s, so it can be use with synchronous and asynchronous generators.
|
||||
|
||||
Here is an example of `IterableElement` in action with a generator function:
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IterableElement} from 'type-fest';
|
||||
|
||||
function * iAmGenerator() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
}
|
||||
|
||||
type MeNumber = IterableElement<ReturnType<typeof iAmGenerator>>
|
||||
```
|
||||
|
||||
And here is an example with an async generator:
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IterableElement} from 'type-fest';
|
||||
|
||||
async function * iAmGeneratorAsync() {
|
||||
yield 'hi';
|
||||
yield true;
|
||||
}
|
||||
|
||||
type MeStringOrBoolean = IterableElement<ReturnType<typeof iAmGeneratorAsync>>
|
||||
```
|
||||
|
||||
Many types in JavaScript/TypeScript are iterables. This type works on all types that implement those interfaces.
|
||||
|
||||
An example with an array of strings:
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IterableElement} from 'type-fest';
|
||||
|
||||
type MeString = IterableElement<string[]>
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IterableElement} from 'type-fest';
|
||||
|
||||
const fruits = new Set(['🍎', '🍌', '🍉'] as const);
|
||||
|
||||
type Fruit = IterableElement<typeof fruits>;
|
||||
//=> '🍎' | '🍌' | '🍉'
|
||||
```
|
||||
|
||||
@category Iterable
|
||||
*/
|
||||
export type IterableElement<TargetIterable> =
|
||||
TargetIterable extends Iterable<infer ElementType> ?
|
||||
ElementType :
|
||||
TargetIterable extends AsyncIterable<infer ElementType> ?
|
||||
ElementType :
|
||||
never;
|
68
node_modules/type-fest/source/join.d.ts
generated
vendored
Normal file
68
node_modules/type-fest/source/join.d.ts
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// The builtin `join` method supports all these natively in the same way that typescript handles them so we can safely accept all of them.
|
||||
type JoinableItem = string | number | bigint | boolean | undefined | null;
|
||||
|
||||
// `null` and `undefined` are treated uniquely in the built-in join method, in a way that differs from the default `toString` that would result in the type `${undefined}`. That's why we need to handle it specifically with this helper.
|
||||
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join#description
|
||||
type NullishCoalesce<
|
||||
Value extends JoinableItem,
|
||||
Fallback extends string,
|
||||
> = Value extends undefined | null ? NonNullable<Value> | Fallback : Value;
|
||||
|
||||
/**
|
||||
Join an array of strings and/or numbers using the given string as a delimiter.
|
||||
|
||||
Use-case: Defining key paths in a nested object. For example, for dot-notation fields in MongoDB queries.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Join} from 'type-fest';
|
||||
|
||||
// Mixed (strings & numbers) items; result is: 'foo.0.baz'
|
||||
const path: Join<['foo', 0, 'baz'], '.'> = ['foo', 0, 'baz'].join('.');
|
||||
|
||||
// Only string items; result is: 'foo.bar.baz'
|
||||
const path: Join<['foo', 'bar', 'baz'], '.'> = ['foo', 'bar', 'baz'].join('.');
|
||||
|
||||
// Only number items; result is: '1.2.3'
|
||||
const path: Join<[1, 2, 3], '.'> = [1, 2, 3].join('.');
|
||||
|
||||
// Only bigint items; result is '1.2.3'
|
||||
const path: Join<[1n, 2n, 3n], '.'> = [1n, 2n, 3n].join('.');
|
||||
|
||||
// Only boolean items; result is: 'true.false.true'
|
||||
const path: Join<[true, false, true], '.'> = [true, false, true].join('.');
|
||||
|
||||
// Contains nullish items; result is: 'foo..baz..xyz'
|
||||
const path: Join<['foo', undefined, 'baz', null, 'xyz'], '.'> = ['foo', undefined, 'baz', null, 'xyz'].join('.');
|
||||
|
||||
// Partial tuple shapes (rest param last); result is: `prefix.${string}`
|
||||
const path: Join<['prefix', ...string[]], '.'> = ['prefix'].join('.');
|
||||
|
||||
// Partial tuple shapes (rest param first); result is: `${string}.suffix`
|
||||
const path: Join<[...string[], 'suffix'], '.'> = ['suffix'].join('.');
|
||||
|
||||
// Tuples items with nullish unions; result is '.' | 'hello.' | '.world' | 'hello.world'
|
||||
const path: Join<['hello' | undefined, 'world' | null], '.'> = ['hello', 'world'].join('.');
|
||||
```
|
||||
|
||||
@category Array
|
||||
@category Template literal
|
||||
*/
|
||||
export type Join<
|
||||
Items extends readonly JoinableItem[],
|
||||
Delimiter extends string,
|
||||
> = Items extends readonly []
|
||||
? ''
|
||||
: Items extends readonly [JoinableItem?]
|
||||
? `${NullishCoalesce<Items[0], ''>}`
|
||||
: Items extends readonly [
|
||||
infer First extends JoinableItem,
|
||||
...infer Tail extends readonly JoinableItem[],
|
||||
]
|
||||
? `${NullishCoalesce<First, ''>}${Delimiter}${Join<Tail, Delimiter>}`
|
||||
: Items extends readonly [
|
||||
...infer Head extends readonly JoinableItem[],
|
||||
infer Last extends JoinableItem,
|
||||
]
|
||||
? `${Join<Head, Delimiter>}${Delimiter}${NullishCoalesce<Last, ''>}`
|
||||
: string;
|
37
node_modules/type-fest/source/jsonifiable.d.ts
generated
vendored
Normal file
37
node_modules/type-fest/source/jsonifiable.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import type {JsonPrimitive} from './basic';
|
||||
|
||||
type JsonifiableObject = {[Key in string]?: Jsonifiable} | {toJSON: () => Jsonifiable};
|
||||
type JsonifiableArray = readonly Jsonifiable[];
|
||||
|
||||
/**
|
||||
Matches a value that can be losslessly converted to JSON.
|
||||
|
||||
Can be used to type values that you expect to pass to `JSON.stringify`.
|
||||
|
||||
`undefined` is allowed in object fields (for example, `{a?: number}`) as a special case even though `JSON.stringify({a: undefined})` is `{}` because it makes this class more widely useful and checking for undefined-but-present values is likely an anti-pattern.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Jsonifiable} from 'type-fest';
|
||||
|
||||
// @ts-expect-error
|
||||
const error: Jsonifiable = {
|
||||
map: new Map([['a', 1]]),
|
||||
};
|
||||
|
||||
JSON.stringify(error);
|
||||
//=> {"map": {}}
|
||||
|
||||
const good: Jsonifiable = {
|
||||
number: 3,
|
||||
date: new Date(),
|
||||
missing: undefined,
|
||||
}
|
||||
|
||||
JSON.stringify(good);
|
||||
//=> {"number": 3, "date": "2022-10-17T22:22:35.920Z"}
|
||||
```
|
||||
|
||||
@category JSON
|
||||
*/
|
||||
export type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
|
122
node_modules/type-fest/source/jsonify.d.ts
generated
vendored
Normal file
122
node_modules/type-fest/source/jsonify.d.ts
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
import type {JsonPrimitive, JsonValue} from './basic';
|
||||
import type {EmptyObject} from './empty-object';
|
||||
import type {UndefinedToOptional} from './internal';
|
||||
import type {IsAny} from './is-any';
|
||||
import type {IsNever} from './is-never';
|
||||
import type {IsUnknown} from './is-unknown';
|
||||
import type {NegativeInfinity, PositiveInfinity} from './numeric';
|
||||
import type {TypedArray} from './typed-array';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
// Note: The return value has to be `any` and not `unknown` so it can match `void`.
|
||||
type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
|
||||
|
||||
type NeverToNull<T> = IsNever<T> extends true ? null : T;
|
||||
type UndefinedToNull<T> = T extends undefined ? null : T;
|
||||
|
||||
// Handles tuples and arrays
|
||||
type JsonifyList<T extends UnknownArray> = T extends readonly []
|
||||
? []
|
||||
: T extends readonly [infer F, ...infer R]
|
||||
? [NeverToNull<Jsonify<F>>, ...JsonifyList<R>]
|
||||
: IsUnknown<T[number]> extends true
|
||||
? []
|
||||
: Array<T[number] extends NotJsonable ? null : Jsonify<UndefinedToNull<T[number]>>>;
|
||||
|
||||
type FilterJsonableKeys<T extends object> = {
|
||||
[Key in keyof T]: T[Key] extends NotJsonable ? never : Key;
|
||||
}[keyof T];
|
||||
|
||||
/**
|
||||
JSON serialize objects (not including arrays) and classes.
|
||||
*/
|
||||
type JsonifyObject<T extends object> = {
|
||||
[Key in keyof Pick<T, FilterJsonableKeys<T>>]: Jsonify<T[Key]>;
|
||||
};
|
||||
|
||||
/**
|
||||
Transform a type to one that is assignable to the `JsonValue` type.
|
||||
|
||||
This includes:
|
||||
1. Transforming JSON `interface` to a `type` that is assignable to `JsonValue`.
|
||||
2. Transforming non-JSON value that is *jsonable* to a type that is assignable to `JsonValue`, where *jsonable* means the non-JSON value implements the `.toJSON()` method that returns a value that is assignable to `JsonValue`.
|
||||
|
||||
@remarks
|
||||
|
||||
An interface cannot be structurally compared to `JsonValue` because an interface can be re-opened to add properties that may not be satisfy `JsonValue`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Jsonify, JsonValue} from 'type-fest';
|
||||
|
||||
interface Geometry {
|
||||
type: 'Point' | 'Polygon';
|
||||
coordinates: [number, number];
|
||||
}
|
||||
|
||||
const point: Geometry = {
|
||||
type: 'Point',
|
||||
coordinates: [1, 1]
|
||||
};
|
||||
|
||||
const problemFn = (data: JsonValue) => {
|
||||
// Does something with data
|
||||
};
|
||||
|
||||
problemFn(point); // Error: type Geometry is not assignable to parameter of type JsonValue because it is an interface
|
||||
|
||||
const fixedFn = <T>(data: Jsonify<T>) => {
|
||||
// Does something with data
|
||||
};
|
||||
|
||||
fixedFn(point); // Good: point is assignable. Jsonify<T> transforms Geometry into value assignable to JsonValue
|
||||
fixedFn(new Date()); // Error: As expected, Date is not assignable. Jsonify<T> cannot transforms Date into value assignable to JsonValue
|
||||
```
|
||||
|
||||
Non-JSON values such as `Date` implement `.toJSON()`, so they can be transformed to a value assignable to `JsonValue`:
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Jsonify} from 'type-fest';
|
||||
|
||||
const time = {
|
||||
timeValue: new Date()
|
||||
};
|
||||
|
||||
// `Jsonify<typeof time>` is equivalent to `{timeValue: string}`
|
||||
const timeJson = JSON.parse(JSON.stringify(time)) as Jsonify<typeof time>;
|
||||
```
|
||||
|
||||
@link https://github.com/Microsoft/TypeScript/issues/1897#issuecomment-710744173
|
||||
|
||||
@category JSON
|
||||
*/
|
||||
export type Jsonify<T> = IsAny<T> extends true
|
||||
? any
|
||||
: T extends PositiveInfinity | NegativeInfinity
|
||||
? null
|
||||
: T extends JsonPrimitive
|
||||
? T
|
||||
: // Any object with toJSON is special case
|
||||
T extends {toJSON(): infer J}
|
||||
? (() => J) extends () => JsonValue // Is J assignable to JsonValue?
|
||||
? J // Then T is Jsonable and its Jsonable value is J
|
||||
: Jsonify<J> // Maybe if we look a level deeper we'll find a JsonValue
|
||||
: // Instanced primitives are objects
|
||||
T extends Number
|
||||
? number
|
||||
: T extends String
|
||||
? string
|
||||
: T extends Boolean
|
||||
? boolean
|
||||
: T extends Map<any, any> | Set<any>
|
||||
? EmptyObject
|
||||
: T extends TypedArray
|
||||
? Record<string, number>
|
||||
: T extends NotJsonable
|
||||
? never // Non-JSONable type union was found not empty
|
||||
: T extends UnknownArray
|
||||
? JsonifyList<T>
|
||||
: T extends object
|
||||
? JsonifyObject<UndefinedToOptional<T>> // JsonifyObject recursive call for its children
|
||||
: never; // Otherwise any other non-object is removed
|
44
node_modules/type-fest/source/kebab-case.d.ts
generated
vendored
Normal file
44
node_modules/type-fest/source/kebab-case.d.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case';
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {WordsOptions} from './words';
|
||||
|
||||
/**
|
||||
Convert a string literal to kebab-case.
|
||||
|
||||
This can be useful when, for example, converting a camel-cased object property to a kebab-cased CSS class name or a command-line flag.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {KebabCase} from 'type-fest';
|
||||
|
||||
// Simple
|
||||
|
||||
const someVariable: KebabCase<'fooBar'> = 'foo-bar';
|
||||
const someVariableNoSplitOnNumbers: KebabCase<'p2pNetwork', {splitOnNumbers: false}> = 'p2p-network';
|
||||
|
||||
// Advanced
|
||||
|
||||
type KebabCasedProperties<T> = {
|
||||
[K in keyof T as KebabCase<K>]: T[K]
|
||||
};
|
||||
|
||||
interface CliOptions {
|
||||
dryRun: boolean;
|
||||
includeFile: string;
|
||||
foo: number;
|
||||
}
|
||||
|
||||
const rawCliOptions: KebabCasedProperties<CliOptions> = {
|
||||
'dry-run': true,
|
||||
'include-file': 'bar.js',
|
||||
foo: 123
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
*/
|
||||
export type KebabCase<
|
||||
Value,
|
||||
Options extends WordsOptions = {},
|
||||
> = DelimiterCase<Value, '-', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
63
node_modules/type-fest/source/kebab-cased-properties-deep.d.ts
generated
vendored
Normal file
63
node_modules/type-fest/source/kebab-cased-properties-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import type {DefaultDelimiterCaseOptions} from './delimiter-case';
|
||||
import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {WordsOptions} from './words';
|
||||
|
||||
/**
|
||||
Convert object properties to kebab case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see KebabCase
|
||||
@see KebabCasedProperties
|
||||
|
||||
@example
|
||||
```
|
||||
import type [KebabCasedPropertiesDeep] from 'type-fest';
|
||||
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
userInfo: User;
|
||||
userFriends: User[];
|
||||
}
|
||||
|
||||
const result: KebabCasedPropertiesDeep<UserWithFriends> = {
|
||||
'user-info': {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
},
|
||||
'user-friends': [
|
||||
{
|
||||
'user-id': 2,
|
||||
'user-name': 'Jerry',
|
||||
},
|
||||
{
|
||||
'user-id': 3,
|
||||
'user-name': 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const splitOnNumbers: KebabCasedPropertiesDeep<{line1: { line2: [{ line3: string }] }}, {splitOnNumbers: true}> = {
|
||||
'line-1': {
|
||||
'line-2': [
|
||||
{
|
||||
'line-3': 'string',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
@category Object
|
||||
*/
|
||||
export type KebabCasedPropertiesDeep<
|
||||
Value,
|
||||
Options extends WordsOptions = {},
|
||||
> = DelimiterCasedPropertiesDeep<Value, '-', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
40
node_modules/type-fest/source/kebab-cased-properties.d.ts
generated
vendored
Normal file
40
node_modules/type-fest/source/kebab-cased-properties.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import type {DefaultDelimiterCaseOptions} from './delimiter-case';
|
||||
import type {DelimiterCasedProperties} from './delimiter-cased-properties';
|
||||
import type {ApplyDefaultOptions} from './internal';
|
||||
import type {WordsOptions} from './words';
|
||||
|
||||
/**
|
||||
Convert object properties to kebab case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see KebabCase
|
||||
@see KebabCasedPropertiesDeep
|
||||
|
||||
@example
|
||||
```
|
||||
import type {KebabCasedProperties} from 'type-fest';
|
||||
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
const result: KebabCasedProperties<User> = {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
};
|
||||
|
||||
const splitOnNumbers: KebabCasedProperties<{line1: string}, {splitOnNumbers: true}> = {
|
||||
'line-1': 'string',
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
@category Object
|
||||
*/
|
||||
export type KebabCasedProperties<
|
||||
Value,
|
||||
Options extends WordsOptions = {},
|
||||
> = DelimiterCasedProperties<Value, '-', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
|
42
node_modules/type-fest/source/keys-of-union.d.ts
generated
vendored
Normal file
42
node_modules/type-fest/source/keys-of-union.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import type {UnionToIntersection} from './union-to-intersection';
|
||||
|
||||
/**
|
||||
Create a union of all keys from a given type, even those exclusive to specific union members.
|
||||
|
||||
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
||||
|
||||
@link https://stackoverflow.com/a/49402091
|
||||
|
||||
@example
|
||||
```
|
||||
import type {KeysOfUnion} from 'type-fest';
|
||||
|
||||
type A = {
|
||||
common: string;
|
||||
a: number;
|
||||
};
|
||||
|
||||
type B = {
|
||||
common: string;
|
||||
b: string;
|
||||
};
|
||||
|
||||
type C = {
|
||||
common: string;
|
||||
c: boolean;
|
||||
};
|
||||
|
||||
type Union = A | B | C;
|
||||
|
||||
type CommonKeys = keyof Union;
|
||||
//=> 'common'
|
||||
|
||||
type AllKeys = KeysOfUnion<Union>;
|
||||
//=> 'common' | 'a' | 'b' | 'c'
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type KeysOfUnion<ObjectType> =
|
||||
// Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
||||
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
38
node_modules/type-fest/source/last-array-element.d.ts
generated
vendored
Normal file
38
node_modules/type-fest/source/last-array-element.d.ts
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
Extracts the type of the last element of an array.
|
||||
|
||||
Use-case: Defining the return type of functions that extract the last element of an array, for example [`lodash.last`](https://lodash.com/docs/4.17.15#last).
|
||||
|
||||
@example
|
||||
```
|
||||
import type {LastArrayElement} from 'type-fest';
|
||||
|
||||
declare function lastOf<V extends readonly any[]>(array: V): LastArrayElement<V>;
|
||||
|
||||
const array = ['foo', 2];
|
||||
|
||||
typeof lastOf(array);
|
||||
//=> number
|
||||
|
||||
const array = ['foo', 2] as const;
|
||||
|
||||
typeof lastOf(array);
|
||||
//=> 2
|
||||
```
|
||||
|
||||
@category Array
|
||||
@category Template literal
|
||||
*/
|
||||
export type LastArrayElement<Elements extends readonly unknown[], ElementBeforeTailingSpreadElement = never> =
|
||||
// If the last element of an array is a spread element, the `LastArrayElement` result should be `'the type of the element before the spread element' | 'the type of the spread element'`.
|
||||
Elements extends readonly []
|
||||
? ElementBeforeTailingSpreadElement
|
||||
: Elements extends readonly [...infer U, infer V]
|
||||
? V
|
||||
: Elements extends readonly [infer U, ...infer V]
|
||||
// If we return `V[number] | U` directly, it would be wrong for `[[string, boolean, object, ...number[]]`.
|
||||
// So we need to recurse type `V` and carry over the type of the element before the spread element.
|
||||
? LastArrayElement<V, U>
|
||||
: Elements extends ReadonlyArray<infer U>
|
||||
? U | ElementBeforeTailingSpreadElement
|
||||
: never;
|
22
node_modules/type-fest/source/less-than-or-equal.d.ts
generated
vendored
Normal file
22
node_modules/type-fest/source/less-than-or-equal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import type {GreaterThan} from './greater-than';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether a given number is less than or equal to another number.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {LessThanOrEqual} from 'type-fest';
|
||||
|
||||
LessThanOrEqual<1, -5>;
|
||||
//=> false
|
||||
|
||||
LessThanOrEqual<1, 1>;
|
||||
//=> true
|
||||
|
||||
LessThanOrEqual<1, 5>;
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
export type LessThanOrEqual<A extends number, B extends number> = number extends A | B
|
||||
? never
|
||||
: GreaterThan<A, B> extends true ? false : true;
|
26
node_modules/type-fest/source/less-than.d.ts
generated
vendored
Normal file
26
node_modules/type-fest/source/less-than.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type {GreaterThanOrEqual} from './greater-than-or-equal';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether a given number is less than another number.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {LessThan} from 'type-fest';
|
||||
|
||||
LessThan<1, -5>;
|
||||
//=> false
|
||||
|
||||
LessThan<1, 1>;
|
||||
//=> false
|
||||
|
||||
LessThan<1, 5>;
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
export type LessThan<A extends number, B extends number> = number extends A | B
|
||||
? never
|
||||
: GreaterThanOrEqual<A, B> extends infer Result
|
||||
? Result extends true
|
||||
? false
|
||||
: true
|
||||
: never; // Should never happen
|
36
node_modules/type-fest/source/literal-to-primitive-deep.d.ts
generated
vendored
Normal file
36
node_modules/type-fest/source/literal-to-primitive-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import type {LiteralToPrimitive} from './literal-to-primitive';
|
||||
import type {OmitIndexSignature} from './omit-index-signature';
|
||||
|
||||
/**
|
||||
Like `LiteralToPrimitive` except it converts literal types inside an object or array deeply.
|
||||
|
||||
For example, given a constant object, it returns a new object type with the same keys but with all the values converted to primitives.
|
||||
|
||||
@see LiteralToPrimitive
|
||||
|
||||
Use-case: Deal with data that is imported from a JSON file.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {LiteralToPrimitiveDeep, TsConfigJson} from 'type-fest';
|
||||
import tsconfig from 'path/to/tsconfig.json';
|
||||
|
||||
function doSomethingWithTSConfig(config: LiteralToPrimitiveDeep<TsConfigJson>) { ... }
|
||||
|
||||
// No casting is needed to pass the type check
|
||||
doSomethingWithTSConfig(tsconfig);
|
||||
|
||||
// If LiteralToPrimitiveDeep is not used, you need to cast the imported data like this:
|
||||
doSomethingWithTSConfig(tsconfig as TsConfigJson);
|
||||
```
|
||||
|
||||
@category Type
|
||||
@category Object
|
||||
*/
|
||||
export type LiteralToPrimitiveDeep<T> = T extends object
|
||||
? T extends Array<infer U>
|
||||
? Array<LiteralToPrimitiveDeep<U>>
|
||||
: {
|
||||
[K in keyof OmitIndexSignature<T>]: LiteralToPrimitiveDeep<T[K]>;
|
||||
}
|
||||
: LiteralToPrimitive<T>;
|
36
node_modules/type-fest/source/literal-to-primitive.d.ts
generated
vendored
Normal file
36
node_modules/type-fest/source/literal-to-primitive.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the {@link Primitive | primitive type} it belongs to, or `never` if it's not a primitive.
|
||||
|
||||
Use-case: Working with generic types that may be literal types.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {LiteralToPrimitive} from 'type-fest';
|
||||
|
||||
// No overloads needed to get the correct return type
|
||||
function plus<T extends number | bigint | string>(x: T, y: T): LiteralToPrimitive<T> {
|
||||
return x + (y as any);
|
||||
}
|
||||
|
||||
plus('a', 'b'); // string
|
||||
plus(1, 2); // number
|
||||
plus(1n, 2n); // bigint
|
||||
```
|
||||
|
||||
@category Type
|
||||
*/
|
||||
export type LiteralToPrimitive<T> = T extends number
|
||||
? number
|
||||
: T extends bigint
|
||||
? bigint
|
||||
: T extends string
|
||||
? string
|
||||
: T extends boolean
|
||||
? boolean
|
||||
: T extends symbol
|
||||
? symbol
|
||||
: T extends null
|
||||
? null
|
||||
: T extends undefined
|
||||
? undefined
|
||||
: never;
|
37
node_modules/type-fest/source/literal-union.d.ts
generated
vendored
Normal file
37
node_modules/type-fest/source/literal-union.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import type {Primitive} from './primitive';
|
||||
|
||||
export type LiteralStringUnion<T> = LiteralUnion<T, string>;
|
||||
|
||||
/**
|
||||
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
||||
|
||||
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
||||
|
||||
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {LiteralUnion} from 'type-fest';
|
||||
|
||||
// Before
|
||||
|
||||
type Pet = 'dog' | 'cat' | string;
|
||||
|
||||
const pet: Pet = '';
|
||||
// Start typing in your TypeScript-enabled IDE.
|
||||
// You **will not** get auto-completion for `dog` and `cat` literals.
|
||||
|
||||
// After
|
||||
|
||||
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
||||
|
||||
const pet: Pet2 = '';
|
||||
// You **will** get auto-completion for `dog` and `cat` literals.
|
||||
```
|
||||
|
||||
@category Type
|
||||
*/
|
||||
export type LiteralUnion<
|
||||
LiteralType,
|
||||
BaseType extends Primitive,
|
||||
> = LiteralType | (BaseType & Record<never, never>);
|
486
node_modules/type-fest/source/merge-deep.d.ts
generated
vendored
Normal file
486
node_modules/type-fest/source/merge-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,486 @@
|
||||
import type {ConditionalSimplifyDeep} from './conditional-simplify';
|
||||
import type {OmitIndexSignature} from './omit-index-signature';
|
||||
import type {PickIndexSignature} from './pick-index-signature';
|
||||
import type {Merge} from './merge';
|
||||
import type {
|
||||
FirstArrayElement,
|
||||
IsBothExtends,
|
||||
UnknownArrayOrTuple,
|
||||
} from './internal';
|
||||
import type {NonEmptyTuple} from './non-empty-tuple';
|
||||
import type {ArrayTail} from './array-tail';
|
||||
import type {UnknownRecord} from './unknown-record';
|
||||
import type {EnforceOptional} from './enforce-optional';
|
||||
import type {SimplifyDeep} from './simplify-deep';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
type SimplifyDeepExcludeArray<T> = SimplifyDeep<T, UnknownArray>;
|
||||
|
||||
/**
|
||||
Try to merge two record properties or return the source property value, preserving `undefined` properties values in both cases.
|
||||
*/
|
||||
type MergeDeepRecordProperty<
|
||||
Destination,
|
||||
Source,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = undefined extends Source
|
||||
? MergeDeepOrReturn<Source, Exclude<Destination, undefined>, Exclude<Source, undefined>, Options> | undefined
|
||||
: MergeDeepOrReturn<Source, Destination, Source, Options>;
|
||||
|
||||
/**
|
||||
Walk through the union of the keys of the two objects and test in which object the properties are defined.
|
||||
Rules:
|
||||
1. If the source does not contain the key, the value of the destination is returned.
|
||||
2. If the source contains the key and the destination does not contain the key, the value of the source is returned.
|
||||
3. If both contain the key, try to merge according to the chosen {@link MergeDeepOptions options} or return the source if unable to merge.
|
||||
*/
|
||||
type DoMergeDeepRecord<
|
||||
Destination extends UnknownRecord,
|
||||
Source extends UnknownRecord,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> =
|
||||
// Case in rule 1: The destination contains the key but the source doesn't.
|
||||
{
|
||||
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
||||
}
|
||||
// Case in rule 2: The source contains the key but the destination doesn't.
|
||||
& {
|
||||
[Key in keyof Source as Key extends keyof Destination ? never : Key]: Source[Key];
|
||||
}
|
||||
// Case in rule 3: Both the source and the destination contain the key.
|
||||
& {
|
||||
[Key in keyof Source as Key extends keyof Destination ? Key : never]: MergeDeepRecordProperty<Destination[Key], Source[Key], Options>;
|
||||
};
|
||||
|
||||
/**
|
||||
Wrapper around {@link DoMergeDeepRecord} which preserves index signatures.
|
||||
*/
|
||||
type MergeDeepRecord<
|
||||
Destination extends UnknownRecord,
|
||||
Source extends UnknownRecord,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = DoMergeDeepRecord<OmitIndexSignature<Destination>, OmitIndexSignature<Source>, Options>
|
||||
& Merge<PickIndexSignature<Destination>, PickIndexSignature<Source>>;
|
||||
|
||||
// Helper to avoid computing ArrayTail twice.
|
||||
type PickRestTypeHelper<Tail extends UnknownArrayOrTuple, Type> = Tail extends [] ? Type : PickRestType<Tail>;
|
||||
|
||||
/**
|
||||
Pick the rest type.
|
||||
|
||||
@example
|
||||
```
|
||||
type Rest1 = PickRestType<[]>; // => []
|
||||
type Rest2 = PickRestType<[string]>; // => []
|
||||
type Rest3 = PickRestType<[...number[]]>; // => number[]
|
||||
type Rest4 = PickRestType<[string, ...number[]]>; // => number[]
|
||||
type Rest5 = PickRestType<string[]>; // => string[]
|
||||
```
|
||||
*/
|
||||
type PickRestType<Type extends UnknownArrayOrTuple> = number extends Type['length']
|
||||
? PickRestTypeHelper<ArrayTail<Type>, Type>
|
||||
: [];
|
||||
|
||||
// Helper to avoid computing ArrayTail twice.
|
||||
type OmitRestTypeHelper<
|
||||
Tail extends UnknownArrayOrTuple,
|
||||
Type extends UnknownArrayOrTuple,
|
||||
Result extends UnknownArrayOrTuple = [],
|
||||
> = Tail extends []
|
||||
? Result
|
||||
: OmitRestType<Tail, [...Result, FirstArrayElement<Type>]>;
|
||||
|
||||
/**
|
||||
Omit the rest type.
|
||||
|
||||
@example
|
||||
```
|
||||
type Tuple1 = OmitRestType<[]>; // => []
|
||||
type Tuple2 = OmitRestType<[string]>; // => [string]
|
||||
type Tuple3 = OmitRestType<[...number[]]>; // => []
|
||||
type Tuple4 = OmitRestType<[string, ...number[]]>; // => [string]
|
||||
type Tuple5 = OmitRestType<[string, boolean[], ...number[]]>; // => [string, boolean[]]
|
||||
type Tuple6 = OmitRestType<string[]>; // => []
|
||||
```
|
||||
*/
|
||||
type OmitRestType<Type extends UnknownArrayOrTuple, Result extends UnknownArrayOrTuple = []> = number extends Type['length']
|
||||
? OmitRestTypeHelper<ArrayTail<Type>, Type, Result>
|
||||
: Type;
|
||||
|
||||
// Utility to avoid picking two times the type.
|
||||
type TypeNumberOrType<Type extends UnknownArrayOrTuple> = Type[number] extends never ? Type : Type[number];
|
||||
|
||||
// Pick the rest type (array) and try to get the intrinsic type or return the provided type.
|
||||
type PickRestTypeFlat<Type extends UnknownArrayOrTuple> = TypeNumberOrType<PickRestType<Type>>;
|
||||
|
||||
/**
|
||||
Try to merge two array/tuple elements or return the source element if the end of the destination is reached or vis-versa.
|
||||
*/
|
||||
type MergeDeepArrayOrTupleElements<
|
||||
Destination,
|
||||
Source,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = Source extends []
|
||||
? Destination
|
||||
: Destination extends []
|
||||
? Source
|
||||
: MergeDeepOrReturn<Source, Destination, Source, Options>;
|
||||
|
||||
/**
|
||||
Merge two tuples recursively.
|
||||
*/
|
||||
type DoMergeDeepTupleAndTupleRecursive<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
DestinationRestType,
|
||||
SourceRestType,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = Destination extends []
|
||||
? Source extends []
|
||||
? []
|
||||
: MergeArrayTypeAndTuple<DestinationRestType, Source, Options>
|
||||
: Source extends []
|
||||
? MergeTupleAndArrayType<Destination, SourceRestType, Options>
|
||||
: [
|
||||
MergeDeepArrayOrTupleElements<FirstArrayElement<Destination>, FirstArrayElement<Source>, Options>,
|
||||
...DoMergeDeepTupleAndTupleRecursive<ArrayTail<Destination>, ArrayTail<Source>, DestinationRestType, SourceRestType, Options>,
|
||||
];
|
||||
|
||||
/**
|
||||
Merge two tuples recursively taking into account a possible rest element.
|
||||
*/
|
||||
type MergeDeepTupleAndTupleRecursive<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = [
|
||||
...DoMergeDeepTupleAndTupleRecursive<OmitRestType<Destination>, OmitRestType<Source>, PickRestTypeFlat<Destination>, PickRestTypeFlat<Source>, Options>,
|
||||
...MergeDeepArrayOrTupleElements<PickRestType<Destination>, PickRestType<Source>, Options>,
|
||||
];
|
||||
|
||||
/**
|
||||
Merge an array type with a tuple recursively.
|
||||
*/
|
||||
type MergeTupleAndArrayType<
|
||||
Tuple extends UnknownArrayOrTuple,
|
||||
ArrayType,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = Tuple extends []
|
||||
? Tuple
|
||||
: [
|
||||
MergeDeepArrayOrTupleElements<FirstArrayElement<Tuple>, ArrayType, Options>,
|
||||
...MergeTupleAndArrayType<ArrayTail<Tuple>, ArrayType, Options>,
|
||||
];
|
||||
|
||||
/**
|
||||
Merge an array into a tuple recursively taking into account a possible rest element.
|
||||
*/
|
||||
type MergeDeepTupleAndArrayRecursive<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = [
|
||||
...MergeTupleAndArrayType<OmitRestType<Destination>, Source[number], Options>,
|
||||
...MergeDeepArrayOrTupleElements<PickRestType<Destination>, PickRestType<Source>, Options>,
|
||||
];
|
||||
|
||||
/**
|
||||
Merge a tuple with an array type recursively.
|
||||
*/
|
||||
type MergeArrayTypeAndTuple<
|
||||
ArrayType,
|
||||
Tuple extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = Tuple extends []
|
||||
? Tuple
|
||||
: [
|
||||
MergeDeepArrayOrTupleElements<ArrayType, FirstArrayElement<Tuple>, Options>,
|
||||
...MergeArrayTypeAndTuple<ArrayType, ArrayTail<Tuple>, Options>,
|
||||
];
|
||||
|
||||
/**
|
||||
Merge a tuple into an array recursively taking into account a possible rest element.
|
||||
*/
|
||||
type MergeDeepArrayAndTupleRecursive<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = [
|
||||
...MergeArrayTypeAndTuple<Destination[number], OmitRestType<Source>, Options>,
|
||||
...MergeDeepArrayOrTupleElements<PickRestType<Destination>, PickRestType<Source>, Options>,
|
||||
];
|
||||
|
||||
/**
|
||||
Merge mode for array/tuple elements.
|
||||
*/
|
||||
type ArrayMergeMode = 'spread' | 'replace';
|
||||
|
||||
/**
|
||||
Test if it should spread top-level arrays.
|
||||
*/
|
||||
type ShouldSpread<Options extends MergeDeepInternalOptions> = Options['spreadTopLevelArrays'] extends false
|
||||
? Options['arrayMergeMode'] extends 'spread' ? true : false
|
||||
: true;
|
||||
|
||||
/**
|
||||
Merge two arrays/tuples according to the chosen {@link MergeDeepOptions.arrayMergeMode arrayMergeMode} option.
|
||||
*/
|
||||
type DoMergeArrayOrTuple<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = ShouldSpread<Options> extends true
|
||||
? Array<Exclude<Destination, undefined>[number] | Exclude<Source, undefined>[number]>
|
||||
: Source; // 'replace'
|
||||
|
||||
/**
|
||||
Merge two arrays recursively.
|
||||
|
||||
If the two arrays are multi-level, we merge deeply, otherwise we merge the first level only.
|
||||
|
||||
Note: The `[number]` accessor is used to test the type of the second level.
|
||||
*/
|
||||
type MergeDeepArrayRecursive<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = Destination[number] extends UnknownArrayOrTuple
|
||||
? Source[number] extends UnknownArrayOrTuple
|
||||
? Array<MergeDeepArrayOrTupleRecursive<Destination[number], Source[number], Options>>
|
||||
: DoMergeArrayOrTuple<Destination, Source, Options>
|
||||
: Destination[number] extends UnknownRecord
|
||||
? Source[number] extends UnknownRecord
|
||||
? Array<SimplifyDeepExcludeArray<MergeDeepRecord<Destination[number], Source[number], Options>>>
|
||||
: DoMergeArrayOrTuple<Destination, Source, Options>
|
||||
: DoMergeArrayOrTuple<Destination, Source, Options>;
|
||||
|
||||
/**
|
||||
Merge two array/tuple recursively by selecting one of the four strategies according to the type of inputs.
|
||||
|
||||
- tuple/tuple
|
||||
- tuple/array
|
||||
- array/tuple
|
||||
- array/array
|
||||
*/
|
||||
type MergeDeepArrayOrTupleRecursive<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = IsBothExtends<NonEmptyTuple, Destination, Source> extends true
|
||||
? MergeDeepTupleAndTupleRecursive<Destination, Source, Options>
|
||||
: Destination extends NonEmptyTuple
|
||||
? MergeDeepTupleAndArrayRecursive<Destination, Source, Options>
|
||||
: Source extends NonEmptyTuple
|
||||
? MergeDeepArrayAndTupleRecursive<Destination, Source, Options>
|
||||
: MergeDeepArrayRecursive<Destination, Source, Options>;
|
||||
|
||||
/**
|
||||
Merge two array/tuple according to {@link MergeDeepOptions.recurseIntoArrays recurseIntoArrays} option.
|
||||
*/
|
||||
type MergeDeepArrayOrTuple<
|
||||
Destination extends UnknownArrayOrTuple,
|
||||
Source extends UnknownArrayOrTuple,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = Options['recurseIntoArrays'] extends true
|
||||
? MergeDeepArrayOrTupleRecursive<Destination, Source, Options>
|
||||
: DoMergeArrayOrTuple<Destination, Source, Options>;
|
||||
|
||||
/**
|
||||
Try to merge two objects or two arrays/tuples recursively into a new type or return the default value.
|
||||
*/
|
||||
type MergeDeepOrReturn<
|
||||
DefaultType,
|
||||
Destination,
|
||||
Source,
|
||||
Options extends MergeDeepInternalOptions,
|
||||
> = SimplifyDeepExcludeArray<[undefined] extends [Destination | Source]
|
||||
? DefaultType
|
||||
: Destination extends UnknownRecord
|
||||
? Source extends UnknownRecord
|
||||
? MergeDeepRecord<Destination, Source, Options>
|
||||
: DefaultType
|
||||
: Destination extends UnknownArrayOrTuple
|
||||
? Source extends UnknownArrayOrTuple
|
||||
? MergeDeepArrayOrTuple<Destination, Source, EnforceOptional<Merge<Options, {spreadTopLevelArrays: false}>>>
|
||||
: DefaultType
|
||||
: DefaultType>;
|
||||
|
||||
/**
|
||||
MergeDeep options.
|
||||
|
||||
@see {@link MergeDeep}
|
||||
*/
|
||||
export type MergeDeepOptions = {
|
||||
/**
|
||||
Merge mode for array and tuple.
|
||||
|
||||
When we walk through the properties of the objects and the same key is found and both are array or tuple, a merge mode must be chosen:
|
||||
- `replace`: Replaces the destination value by the source value. This is the default mode.
|
||||
- `spread`: Spreads the destination and the source values.
|
||||
|
||||
See {@link MergeDeep} for usages and examples.
|
||||
|
||||
Note: Top-level arrays and tuples are always spread.
|
||||
|
||||
@default 'replace'
|
||||
*/
|
||||
arrayMergeMode?: ArrayMergeMode;
|
||||
|
||||
/**
|
||||
Whether to affect the individual elements of arrays and tuples.
|
||||
|
||||
If this option is set to `true` the following rules are applied:
|
||||
- If the source does not contain the key, the value of the destination is returned.
|
||||
- If the source contains the key and the destination does not contain the key, the value of the source is returned.
|
||||
- If both contain the key, try to merge according to the chosen {@link MergeDeepOptions.arrayMergeMode arrayMergeMode} or return the source if unable to merge.
|
||||
|
||||
@default false
|
||||
*/
|
||||
recurseIntoArrays?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
Internal options.
|
||||
*/
|
||||
type MergeDeepInternalOptions = Merge<MergeDeepOptions, {spreadTopLevelArrays?: boolean}>;
|
||||
|
||||
/**
|
||||
Merge default and internal options with user provided options.
|
||||
*/
|
||||
type DefaultMergeDeepOptions<Options extends MergeDeepOptions> = Merge<{
|
||||
arrayMergeMode: 'replace';
|
||||
recurseIntoArrays: false;
|
||||
spreadTopLevelArrays: true;
|
||||
}, Options>;
|
||||
|
||||
/**
|
||||
This utility selects the correct entry point with the corresponding default options. This avoids re-merging the options at each iteration.
|
||||
*/
|
||||
type MergeDeepWithDefaultOptions<Destination, Source, Options extends MergeDeepOptions> = SimplifyDeepExcludeArray<
|
||||
[undefined] extends [Destination | Source]
|
||||
? never
|
||||
: Destination extends UnknownRecord
|
||||
? Source extends UnknownRecord
|
||||
? MergeDeepRecord<Destination, Source, DefaultMergeDeepOptions<Options>>
|
||||
: never
|
||||
: Destination extends UnknownArrayOrTuple
|
||||
? Source extends UnknownArrayOrTuple
|
||||
? MergeDeepArrayOrTuple<Destination, Source, DefaultMergeDeepOptions<Options>>
|
||||
: never
|
||||
: never
|
||||
>;
|
||||
|
||||
/**
|
||||
Merge two objects or two arrays/tuples recursively into a new type.
|
||||
|
||||
- Properties that only exist in one object are copied into the new object.
|
||||
- Properties that exist in both objects are merged if possible or replaced by the one of the source if not.
|
||||
- Top-level arrays and tuples are always spread.
|
||||
- By default, inner arrays and tuples are replaced. See {@link MergeDeepOptions.arrayMergeMode arrayMergeMode} option to change this behaviour.
|
||||
- By default, individual array/tuple elements are not affected. See {@link MergeDeepOptions.recurseIntoArrays recurseIntoArrays} option to change this behaviour.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MergeDeep} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
life: number;
|
||||
items: string[];
|
||||
a: {b: string; c: boolean; d: number[]};
|
||||
};
|
||||
|
||||
interface Bar {
|
||||
name: string;
|
||||
items: number[];
|
||||
a: {b: number; d: boolean[]};
|
||||
}
|
||||
|
||||
type FooBar = MergeDeep<Foo, Bar>;
|
||||
// {
|
||||
// life: number;
|
||||
// name: string;
|
||||
// items: number[];
|
||||
// a: {b: number; c: boolean; d: boolean[]};
|
||||
// }
|
||||
|
||||
type FooBar = MergeDeep<Foo, Bar, {arrayMergeMode: 'spread'}>;
|
||||
// {
|
||||
// life: number;
|
||||
// name: string;
|
||||
// items: (string | number)[];
|
||||
// a: {b: number; c: boolean; d: (number | boolean)[]};
|
||||
// }
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MergeDeep} from 'type-fest';
|
||||
|
||||
// Merge two arrays
|
||||
type ArrayMerge = MergeDeep<string[], number[]>; // => (string | number)[]
|
||||
|
||||
// Merge two tuples
|
||||
type TupleMerge = MergeDeep<[1, 2, 3], ['a', 'b']>; // => (1 | 2 | 3 | 'a' | 'b')[]
|
||||
|
||||
// Merge an array into a tuple
|
||||
type TupleArrayMerge = MergeDeep<[1, 2, 3], string[]>; // => (string | 1 | 2 | 3)[]
|
||||
|
||||
// Merge a tuple into an array
|
||||
type ArrayTupleMerge = MergeDeep<number[], ['a', 'b']>; // => (number | 'b' | 'a')[]
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MergeDeep, MergeDeepOptions} from 'type-fest';
|
||||
|
||||
type Foo = {foo: 'foo'; fooBar: string[]};
|
||||
type Bar = {bar: 'bar'; fooBar: number[]};
|
||||
|
||||
type FooBar = MergeDeep<Foo, Bar>;
|
||||
// { foo: "foo"; bar: "bar"; fooBar: number[]}
|
||||
|
||||
type FooBarSpread = MergeDeep<Foo, Bar, {arrayMergeMode: 'spread'}>;
|
||||
// { foo: "foo"; bar: "bar"; fooBar: (string | number)[]}
|
||||
|
||||
type FooBarArray = MergeDeep<Foo[], Bar[]>;
|
||||
// (Foo | Bar)[]
|
||||
|
||||
type FooBarArrayDeep = MergeDeep<Foo[], Bar[], {recurseIntoArrays: true}>;
|
||||
// FooBar[]
|
||||
|
||||
type FooBarArraySpreadDeep = MergeDeep<Foo[], Bar[], {recurseIntoArrays: true; arrayMergeMode: 'spread'}>;
|
||||
// FooBarSpread[]
|
||||
|
||||
type FooBarTupleDeep = MergeDeep<[Foo, true, 42], [Bar, 'life'], {recurseIntoArrays: true}>;
|
||||
// [FooBar, 'life', 42]
|
||||
|
||||
type FooBarTupleWithArrayDeep = MergeDeep<[Foo[], true], [Bar[], 'life', 42], {recurseIntoArrays: true}>;
|
||||
// [FooBar[], 'life', 42]
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MergeDeep, MergeDeepOptions} from 'type-fest';
|
||||
|
||||
function mergeDeep<Destination, Source, Options extends MergeDeepOptions = {}>(
|
||||
destination: Destination,
|
||||
source: Source,
|
||||
options?: Options,
|
||||
): MergeDeep<Destination, Source, Options> {
|
||||
// Make your implementation ...
|
||||
}
|
||||
```
|
||||
|
||||
@experimental This type is marked as experimental because it depends on {@link ConditionalSimplifyDeep} which itself is experimental.
|
||||
|
||||
@see {@link MergeDeepOptions}
|
||||
|
||||
@category Array
|
||||
@category Object
|
||||
@category Utilities
|
||||
*/
|
||||
export type MergeDeep<Destination, Source, Options extends MergeDeepOptions = {}> = MergeDeepWithDefaultOptions<
|
||||
SimplifyDeepExcludeArray<Destination>,
|
||||
SimplifyDeepExcludeArray<Source>,
|
||||
Options
|
||||
>;
|
41
node_modules/type-fest/source/merge-exclusive.d.ts
generated
vendored
Normal file
41
node_modules/type-fest/source/merge-exclusive.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// Helper type. Not useful on its own.
|
||||
type Without<FirstType, SecondType> = {[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never};
|
||||
|
||||
/**
|
||||
Create a type that has mutually exclusive keys.
|
||||
|
||||
This type was inspired by [this comment](https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604).
|
||||
|
||||
This type works with a helper type, called `Without`. `Without<FirstType, SecondType>` produces a type that has only keys from `FirstType` which are not present on `SecondType` and sets the value type for these keys to `never`. This helper type is then used in `MergeExclusive` to remove keys from either `FirstType` or `SecondType`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MergeExclusive} from 'type-fest';
|
||||
|
||||
interface ExclusiveVariation1 {
|
||||
exclusive1: boolean;
|
||||
}
|
||||
|
||||
interface ExclusiveVariation2 {
|
||||
exclusive2: string;
|
||||
}
|
||||
|
||||
type ExclusiveOptions = MergeExclusive<ExclusiveVariation1, ExclusiveVariation2>;
|
||||
|
||||
let exclusiveOptions: ExclusiveOptions;
|
||||
|
||||
exclusiveOptions = {exclusive1: true};
|
||||
//=> Works
|
||||
exclusiveOptions = {exclusive2: 'hi'};
|
||||
//=> Works
|
||||
exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
|
||||
//=> Error
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type MergeExclusive<FirstType, SecondType> =
|
||||
(FirstType | SecondType) extends object ?
|
||||
(Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
|
||||
FirstType | SecondType;
|
||||
|
48
node_modules/type-fest/source/merge.d.ts
generated
vendored
Normal file
48
node_modules/type-fest/source/merge.d.ts
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import type {OmitIndexSignature} from './omit-index-signature';
|
||||
import type {PickIndexSignature} from './pick-index-signature';
|
||||
import type {Simplify} from './simplify';
|
||||
|
||||
// Merges two objects without worrying about index signatures.
|
||||
type SimpleMerge<Destination, Source> = {
|
||||
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
||||
} & Source;
|
||||
|
||||
/**
|
||||
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Merge} from 'type-fest';
|
||||
|
||||
interface Foo {
|
||||
[x: string]: unknown;
|
||||
[x: number]: unknown;
|
||||
foo: string;
|
||||
bar: symbol;
|
||||
}
|
||||
|
||||
type Bar = {
|
||||
[x: number]: number;
|
||||
[x: symbol]: unknown;
|
||||
bar: Date;
|
||||
baz: boolean;
|
||||
};
|
||||
|
||||
export type FooBar = Merge<Foo, Bar>;
|
||||
// => {
|
||||
// [x: string]: unknown;
|
||||
// [x: number]: number;
|
||||
// [x: symbol]: unknown;
|
||||
// foo: string;
|
||||
// bar: Date;
|
||||
// baz: boolean;
|
||||
// }
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type Merge<Destination, Source> =
|
||||
Simplify<
|
||||
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
||||
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
||||
>;
|
44
node_modules/type-fest/source/multidimensional-array.d.ts
generated
vendored
Normal file
44
node_modules/type-fest/source/multidimensional-array.d.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import type {Subtract} from './subtract';
|
||||
import type {IsEqual} from './is-equal';
|
||||
|
||||
type Recursive<T> = Array<Recursive<T>>;
|
||||
|
||||
/**
|
||||
Creates a type that represents a multidimensional array of the given type and dimension.
|
||||
|
||||
Use-cases:
|
||||
- Return a n-dimensional array from functions.
|
||||
- Declare a n-dimensional array by defining its dimensions rather than declaring `[]` repetitively.
|
||||
- Infer the dimensions of a n-dimensional array automatically from function arguments.
|
||||
- Avoid the need to know in advance the dimensions of a n-dimensional array allowing them to be dynamic.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MultidimensionalArray} from 'type-fest';
|
||||
|
||||
function emptyMatrix<T extends number>(dimensions: T): MultidimensionalArray<unknown, T> {
|
||||
const matrix: unknown[] = [];
|
||||
|
||||
let subMatrix = matrix;
|
||||
for (let dimension = 1; dimension < dimensions; ++dimension) {
|
||||
console.log(`Initializing dimension #${dimension}`);
|
||||
|
||||
subMatrix[0] = [];
|
||||
subMatrix = subMatrix[0] as unknown[];
|
||||
}
|
||||
|
||||
return matrix as MultidimensionalArray<unknown, T>;
|
||||
}
|
||||
|
||||
const matrix = emptyMatrix(3);
|
||||
|
||||
matrix[0][0][0] = 42;
|
||||
```
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type MultidimensionalArray<Element, Dimensions extends number> = number extends Dimensions
|
||||
? Recursive<Element>
|
||||
: IsEqual<Dimensions, 0> extends true
|
||||
? Element
|
||||
: Array<MultidimensionalArray<Element, Subtract<Dimensions, 1>>>;
|
48
node_modules/type-fest/source/multidimensional-readonly-array.d.ts
generated
vendored
Normal file
48
node_modules/type-fest/source/multidimensional-readonly-array.d.ts
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import type {Subtract} from './subtract';
|
||||
import type {IsEqual} from './is-equal';
|
||||
|
||||
type Recursive<T> = ReadonlyArray<Recursive<T>>;
|
||||
|
||||
/**
|
||||
Creates a type that represents a multidimensional readonly array that of the given type and dimension.
|
||||
|
||||
Use-cases:
|
||||
- Return a n-dimensional array from functions.
|
||||
- Declare a n-dimensional array by defining its dimensions rather than declaring `[]` repetitively.
|
||||
- Infer the dimensions of a n-dimensional array automatically from function arguments.
|
||||
- Avoid the need to know in advance the dimensions of a n-dimensional array allowing them to be dynamic.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {MultidimensionalReadonlyArray} from 'type-fest';
|
||||
|
||||
function emptyMatrix<T extends number>(dimensions: T): MultidimensionalReadonlyArray<unknown, T> {
|
||||
const matrix: unknown[] = [];
|
||||
|
||||
let subMatrix = matrix;
|
||||
for (let dimension = 1; dimension < dimensions; ++dimension) {
|
||||
console.log(`Initializing dimension #${dimension}`);
|
||||
|
||||
subMatrix[0] = [];
|
||||
if (dimension < dimensions - 1) {
|
||||
subMatrix = subMatrix[0] as unknown[];
|
||||
} else {
|
||||
subMatrix[0] = 42;
|
||||
}
|
||||
}
|
||||
|
||||
return matrix as MultidimensionalReadonlyArray<unknown, T>;
|
||||
}
|
||||
|
||||
const matrix = emptyMatrix(3);
|
||||
|
||||
const answer = matrix[0][0][0]; // 42
|
||||
```
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type MultidimensionalReadonlyArray<Element, Dimensions extends number> = number extends Dimensions
|
||||
? Recursive<Element>
|
||||
: IsEqual<Dimensions, 0> extends true
|
||||
? Element
|
||||
: ReadonlyArray<MultidimensionalReadonlyArray<Element, Subtract<Dimensions, 1>>>;
|
35
node_modules/type-fest/source/non-empty-object.d.ts
generated
vendored
Normal file
35
node_modules/type-fest/source/non-empty-object.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import type {HasRequiredKeys} from './has-required-keys';
|
||||
import type {RequireAtLeastOne} from './require-at-least-one';
|
||||
|
||||
/**
|
||||
Represents an object with at least 1 non-optional key.
|
||||
|
||||
This is useful when you need an object where all keys are optional, but there must be at least 1 key.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {NonEmptyObject} from 'type-fest';
|
||||
|
||||
type User = {
|
||||
name: string;
|
||||
surname: string;
|
||||
id: number;
|
||||
};
|
||||
|
||||
type UpdateRequest<Entity extends object> = NonEmptyObject<Partial<Entity>>;
|
||||
|
||||
const update1: UpdateRequest<User> = {
|
||||
name: 'Alice',
|
||||
surname: 'Acme',
|
||||
};
|
||||
|
||||
// At least 1 key is required, therefore this will report a 2322 error:
|
||||
// Type '{}' is not assignable to type 'UpdateRequest<User>'
|
||||
const update2: UpdateRequest<User> = {};
|
||||
```
|
||||
|
||||
@see Use `IsEmptyObject` to check whether an object is empty.
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type NonEmptyObject<T extends object> = HasRequiredKeys<T> extends true ? T : RequireAtLeastOne<T, keyof T>;
|
28
node_modules/type-fest/source/non-empty-string.d.ts
generated
vendored
Normal file
28
node_modules/type-fest/source/non-empty-string.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
Matches any non-empty string.
|
||||
|
||||
This is useful when you need a string that is not empty, for example, as a function parameter.
|
||||
|
||||
NOTE:
|
||||
- This returns `never` not just when instantiated with an empty string, but also when an empty string is a subtype of the instantiated type, like `string` or `Uppercase<string>`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {NonEmptyString} from 'type-fest';
|
||||
|
||||
declare function foo<T extends string>(string: NonEmptyString<T>): void;
|
||||
|
||||
foo('a');
|
||||
//=> OK
|
||||
|
||||
foo('');
|
||||
//=> Error: Argument of type '""' is not assignable to parameter of type 'never'.
|
||||
|
||||
declare const someString: string
|
||||
foo(someString);
|
||||
//=> Error: Argument of type 'string' is not assignable to parameter of type 'never'.
|
||||
```
|
||||
|
||||
@category String
|
||||
*/
|
||||
export type NonEmptyString<T extends string> = '' extends T ? never : T;
|
21
node_modules/type-fest/source/non-empty-tuple.d.ts
generated
vendored
Normal file
21
node_modules/type-fest/source/non-empty-tuple.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
Matches any non-empty tuple.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {NonEmptyTuple} from 'type-fest';
|
||||
|
||||
const sum = (...numbers: NonEmptyTuple<number>) => numbers.reduce((total, value) => total + value, 0);
|
||||
|
||||
sum(1, 2, 3);
|
||||
//=> 6
|
||||
|
||||
sum();
|
||||
//=> Error: Expected at least 1 arguments, but got 0.
|
||||
```
|
||||
|
||||
@see {@link RequireAtLeastOne} for objects
|
||||
|
||||
@category Array
|
||||
*/
|
||||
export type NonEmptyTuple<T = unknown> = readonly [T, ...T[]];
|
222
node_modules/type-fest/source/numeric.d.ts
generated
vendored
Normal file
222
node_modules/type-fest/source/numeric.d.ts
generated
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
import type {IsFloat} from './is-float';
|
||||
import type {IsInteger} from './is-integer';
|
||||
|
||||
export type Numeric = number | bigint;
|
||||
|
||||
export type Zero = 0 | 0n;
|
||||
|
||||
/**
|
||||
Matches the hidden `Infinity` type.
|
||||
|
||||
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
||||
|
||||
@see NegativeInfinity
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
// See https://github.com/microsoft/TypeScript/issues/31752
|
||||
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
||||
export type PositiveInfinity = 1e999;
|
||||
|
||||
/**
|
||||
Matches the hidden `-Infinity` type.
|
||||
|
||||
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
||||
|
||||
@see PositiveInfinity
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
// See https://github.com/microsoft/TypeScript/issues/31752
|
||||
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
||||
export type NegativeInfinity = -1e999;
|
||||
|
||||
/**
|
||||
A finite `number`.
|
||||
You can't pass a `bigint` as they are already guaranteed to be finite.
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
Note: This can't detect `NaN`, please upvote [this issue](https://github.com/microsoft/TypeScript/issues/28682) if you want to have this type as a built-in in TypeScript.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Finite} from 'type-fest';
|
||||
|
||||
declare function setScore<T extends number>(length: Finite<T>): void;
|
||||
```
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type Finite<T extends number> = T extends PositiveInfinity | NegativeInfinity ? never : T;
|
||||
|
||||
/**
|
||||
A `number` that is an integer.
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
@example
|
||||
```
|
||||
type Integer = Integer<1>;
|
||||
//=> 1
|
||||
|
||||
type IntegerWithDecimal = Integer<1.0>;
|
||||
//=> 1
|
||||
|
||||
type NegativeInteger = Integer<-1>;
|
||||
//=> -1
|
||||
|
||||
type Float = Integer<1.5>;
|
||||
//=> never
|
||||
|
||||
// Supports non-decimal numbers
|
||||
|
||||
type OctalInteger: Integer<0o10>;
|
||||
//=> 0o10
|
||||
|
||||
type BinaryInteger: Integer<0b10>;
|
||||
//=> 0b10
|
||||
|
||||
type HexadecimalInteger: Integer<0x10>;
|
||||
//=> 0x10
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Integer} from 'type-fest';
|
||||
|
||||
declare function setYear<T extends number>(length: Integer<T>): void;
|
||||
```
|
||||
|
||||
@see NegativeInteger
|
||||
@see NonNegativeInteger
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
// `${bigint}` is a type that matches a valid bigint literal without the `n` (ex. 1, 0b1, 0o1, 0x1)
|
||||
// Because T is a number and not a string we can effectively use this to filter out any numbers containing decimal points
|
||||
export type Integer<T> =
|
||||
T extends unknown // To distributive type
|
||||
? IsInteger<T> extends true ? T : never
|
||||
: never; // Never happens
|
||||
|
||||
/**
|
||||
A `number` that is not an integer.
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
It does not accept `Infinity`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Float} from 'type-fest';
|
||||
|
||||
declare function setPercentage<T extends number>(length: Float<T>): void;
|
||||
```
|
||||
|
||||
@see Integer
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type Float<T> =
|
||||
T extends unknown // To distributive type
|
||||
? IsFloat<T> extends true ? T : never
|
||||
: never; // Never happens
|
||||
|
||||
/**
|
||||
A negative (`-∞ < x < 0`) `number` that is not an integer.
|
||||
Equivalent to `Negative<Float<T>>`.
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
@see Negative
|
||||
@see Float
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type NegativeFloat<T extends number> = Negative<Float<T>>;
|
||||
|
||||
/**
|
||||
A negative `number`/`bigint` (`-∞ < x < 0`)
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
@see NegativeInteger
|
||||
@see NonNegative
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
||||
|
||||
/**
|
||||
A negative (`-∞ < x < 0`) `number` that is an integer.
|
||||
Equivalent to `Negative<Integer<T>>`.
|
||||
|
||||
You can't pass a `bigint` as they are already guaranteed to be integers, instead use `Negative<T>`.
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
@see Negative
|
||||
@see Integer
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type NegativeInteger<T extends number> = Negative<Integer<T>>;
|
||||
|
||||
/**
|
||||
A non-negative `number`/`bigint` (`0 <= x < ∞`).
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
@see NonNegativeInteger
|
||||
@see Negative
|
||||
|
||||
@example
|
||||
```
|
||||
import type {NonNegative} from 'type-fest';
|
||||
|
||||
declare function setLength<T extends number>(length: NonNegative<T>): void;
|
||||
```
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type NonNegative<T extends Numeric> = T extends Zero ? T : Negative<T> extends never ? T : never;
|
||||
|
||||
/**
|
||||
A non-negative (`0 <= x < ∞`) `number` that is an integer.
|
||||
Equivalent to `NonNegative<Integer<T>>`.
|
||||
|
||||
You can't pass a `bigint` as they are already guaranteed to be integers, instead use `NonNegative<T>`.
|
||||
|
||||
Use-case: Validating and documenting parameters.
|
||||
|
||||
@see NonNegative
|
||||
@see Integer
|
||||
|
||||
@example
|
||||
```
|
||||
import type {NonNegativeInteger} from 'type-fest';
|
||||
|
||||
declare function setLength<T extends number>(length: NonNegativeInteger<T>): void;
|
||||
```
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type NonNegativeInteger<T extends number> = NonNegative<Integer<T>>;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given number is a negative number.
|
||||
|
||||
@see Negative
|
||||
|
||||
@example
|
||||
```
|
||||
import type {IsNegative} from 'type-fest';
|
||||
|
||||
type ShouldBeFalse = IsNegative<1>;
|
||||
type ShouldBeTrue = IsNegative<-1>;
|
||||
```
|
||||
|
||||
@category Numeric
|
||||
*/
|
||||
export type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
|
63
node_modules/type-fest/source/observable-like.d.ts
generated
vendored
Normal file
63
node_modules/type-fest/source/observable-like.d.ts
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
||||
interface SymbolConstructor {
|
||||
readonly observable: symbol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@remarks
|
||||
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
||||
As well, some guidance on making an `Observable` to not include `closed` property.
|
||||
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
||||
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
||||
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
||||
|
||||
@category Observable
|
||||
*/
|
||||
export type Unsubscribable = {
|
||||
unsubscribe(): void;
|
||||
};
|
||||
|
||||
/**
|
||||
@category Observable
|
||||
*/
|
||||
type OnNext<ValueType> = (value: ValueType) => void;
|
||||
/**
|
||||
@category Observable
|
||||
*/
|
||||
type OnError = (error: unknown) => void;
|
||||
/**
|
||||
@category Observable
|
||||
*/
|
||||
type OnComplete = () => void;
|
||||
|
||||
/**
|
||||
@category Observable
|
||||
*/
|
||||
export type Observer<ValueType> = {
|
||||
next: OnNext<ValueType>;
|
||||
error: OnError;
|
||||
complete: OnComplete;
|
||||
};
|
||||
|
||||
/**
|
||||
Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
||||
|
||||
@remarks
|
||||
The TC39 Observable proposal defines 2 forms of `subscribe()`:
|
||||
1. Three callback arguments: `subscribe(observer: OnNext<ValueType>, onError?: OnError, onComplete?: OnComplete): Unsubscribable;`
|
||||
2. A single `observer` argument: (as defined below)
|
||||
|
||||
But `Observable` implementations have evolved to preferring case 2 and some implementations choose not to implement case 1. Therefore, an `ObservableLike` cannot be trusted to implement the first case. (xstream and hand built observerables often do not implement case 1)
|
||||
|
||||
@see https://github.com/tc39/proposal-observable#observable
|
||||
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L246-L259
|
||||
@see https://benlesh.com/posts/learning-observable-by-building-observable/
|
||||
|
||||
@category Observable
|
||||
*/
|
||||
export type ObservableLike<ValueType = unknown> = {
|
||||
subscribe(observer?: Partial<Observer<ValueType>>): Unsubscribable;
|
||||
[Symbol.observable](): ObservableLike<ValueType>;
|
||||
};
|
167
node_modules/type-fest/source/omit-deep.d.ts
generated
vendored
Normal file
167
node_modules/type-fest/source/omit-deep.d.ts
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
import type {ArraySplice} from './array-splice';
|
||||
import type {ExactKey, IsArrayReadonly, NonRecursiveType, SetArrayAccess, ToString} from './internal';
|
||||
import type {IsEqual} from './is-equal';
|
||||
import type {IsNever} from './is-never';
|
||||
import type {LiteralUnion} from './literal-union';
|
||||
import type {Paths} from './paths';
|
||||
import type {SimplifyDeep} from './simplify-deep';
|
||||
import type {UnionToTuple} from './union-to-tuple';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
/**
|
||||
Omit properties from a deeply-nested object.
|
||||
|
||||
It supports recursing into arrays.
|
||||
|
||||
It supports removing specific items from an array, replacing each removed item with unknown at the specified index.
|
||||
|
||||
Use-case: Remove unneeded parts of complex objects.
|
||||
|
||||
Use [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys) if you only need one level deep.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {OmitDeep} from 'type-fest';
|
||||
|
||||
type Info = {
|
||||
userInfo: {
|
||||
name: string;
|
||||
uselessInfo: {
|
||||
foo: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
type UsefulInfo = OmitDeep<Info, 'userInfo.uselessInfo'>;
|
||||
// type UsefulInfo = {
|
||||
// userInfo: {
|
||||
// name: string;
|
||||
// };
|
||||
// };
|
||||
|
||||
// Supports removing multiple paths
|
||||
type Info1 = {
|
||||
userInfo: {
|
||||
name: string;
|
||||
uselessField: string;
|
||||
uselessInfo: {
|
||||
foo: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
type UsefulInfo1 = OmitDeep<Info1, 'userInfo.uselessInfo' | 'userInfo.uselessField'>;
|
||||
// type UsefulInfo1 = {
|
||||
// userInfo: {
|
||||
// name: string;
|
||||
// };
|
||||
// };
|
||||
|
||||
// Supports array
|
||||
type A = OmitDeep<[1, 'foo', 2], 1>;
|
||||
// type A = [1, unknown, 2];
|
||||
|
||||
// Supports recursing into array
|
||||
|
||||
type Info1 = {
|
||||
address: [
|
||||
{
|
||||
street: string
|
||||
},
|
||||
{
|
||||
street2: string,
|
||||
foo: string
|
||||
};
|
||||
];
|
||||
}
|
||||
type AddressInfo = OmitDeep<Info1, 'address.1.foo'>;
|
||||
// type AddressInfo = {
|
||||
// address: [
|
||||
// {
|
||||
// street: string;
|
||||
// },
|
||||
// {
|
||||
// street2: string;
|
||||
// };
|
||||
// ];
|
||||
// };
|
||||
```
|
||||
|
||||
@category Object
|
||||
@category Array
|
||||
*/
|
||||
export type OmitDeep<T, PathUnion extends LiteralUnion<Paths<T>, string>> =
|
||||
SimplifyDeep<
|
||||
OmitDeepHelper<T, UnionToTuple<PathUnion>>,
|
||||
UnknownArray>;
|
||||
|
||||
/**
|
||||
Internal helper for {@link OmitDeep}.
|
||||
|
||||
Recursively transforms `T` by applying {@link OmitDeepWithOnePath} for each path in `PathTuple`.
|
||||
*/
|
||||
type OmitDeepHelper<T, PathTuple extends UnknownArray> =
|
||||
PathTuple extends [infer Path, ...infer RestPaths]
|
||||
? OmitDeepHelper<OmitDeepWithOnePath<T, Path & (string | number)>, RestPaths>
|
||||
: T;
|
||||
|
||||
/**
|
||||
Omit one path from the given object/array.
|
||||
*/
|
||||
type OmitDeepWithOnePath<T, Path extends string | number> =
|
||||
T extends NonRecursiveType
|
||||
? T
|
||||
: T extends UnknownArray ? SetArrayAccess<OmitDeepArrayWithOnePath<T, Path>, IsArrayReadonly<T>>
|
||||
: T extends object ? OmitDeepObjectWithOnePath<T, Path>
|
||||
: T;
|
||||
|
||||
/**
|
||||
Omit one path from the given object.
|
||||
*/
|
||||
type OmitDeepObjectWithOnePath<ObjectT extends object, P extends string | number> =
|
||||
P extends `${infer RecordKeyInPath}.${infer SubPath}`
|
||||
? {
|
||||
[Key in keyof ObjectT]:
|
||||
IsEqual<RecordKeyInPath, ToString<Key>> extends true
|
||||
? ExactKey<ObjectT, Key> extends infer RealKey
|
||||
? RealKey extends keyof ObjectT
|
||||
? OmitDeepWithOnePath<ObjectT[RealKey], SubPath>
|
||||
: ObjectT[Key]
|
||||
: ObjectT[Key]
|
||||
: ObjectT[Key]
|
||||
}
|
||||
: ExactKey<ObjectT, P> extends infer Key
|
||||
? IsNever<Key> extends true
|
||||
? ObjectT
|
||||
: Key extends PropertyKey
|
||||
? Omit<ObjectT, Key>
|
||||
: ObjectT
|
||||
: ObjectT;
|
||||
|
||||
/**
|
||||
Omit one path from from the given array.
|
||||
|
||||
It replaces the item to `unknown` at the given index.
|
||||
|
||||
@example
|
||||
```
|
||||
type A = OmitDeepArrayWithOnePath<[10, 20, 30, 40], 2>;
|
||||
//=> type A = [10, 20, unknown, 40];
|
||||
```
|
||||
*/
|
||||
type OmitDeepArrayWithOnePath<ArrayType extends UnknownArray, P extends string | number> =
|
||||
// Handle paths that are `${number}.${string}`
|
||||
P extends `${infer ArrayIndex extends number}.${infer SubPath}`
|
||||
// If `ArrayIndex` is equal to `number`
|
||||
? number extends ArrayIndex
|
||||
? Array<OmitDeepWithOnePath<NonNullable<ArrayType[number]>, SubPath>>
|
||||
// If `ArrayIndex` is a number literal
|
||||
: ArraySplice<ArrayType, ArrayIndex, 1, [OmitDeepWithOnePath<NonNullable<ArrayType[ArrayIndex]>, SubPath>]>
|
||||
// If the path is equal to `number`
|
||||
: P extends `${infer ArrayIndex extends number}`
|
||||
// If `ArrayIndex` is `number`
|
||||
? number extends ArrayIndex
|
||||
? []
|
||||
// If `ArrayIndex` is a number literal
|
||||
: ArraySplice<ArrayType, ArrayIndex, 1, [unknown]>
|
||||
: ArrayType;
|
95
node_modules/type-fest/source/omit-index-signature.d.ts
generated
vendored
Normal file
95
node_modules/type-fest/source/omit-index-signature.d.ts
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
||||
|
||||
This is the counterpart of `PickIndexSignature`.
|
||||
|
||||
Use-cases:
|
||||
- Remove overly permissive signatures from third-party types.
|
||||
|
||||
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
||||
|
||||
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
||||
|
||||
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
||||
|
||||
```
|
||||
const indexed: Record<string, unknown> = {}; // Allowed
|
||||
|
||||
const keyed: Record<'foo', unknown> = {}; // Error
|
||||
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```
|
||||
type Indexed = {} extends Record<string, unknown>
|
||||
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
||||
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
||||
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
||||
|
||||
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
||||
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
||||
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
||||
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
||||
```
|
||||
|
||||
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`...
|
||||
|
||||
```
|
||||
import type {OmitIndexSignature} from 'type-fest';
|
||||
|
||||
type OmitIndexSignature<ObjectType> = {
|
||||
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
||||
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
||||
};
|
||||
```
|
||||
|
||||
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
||||
|
||||
```
|
||||
import type {OmitIndexSignature} from 'type-fest';
|
||||
|
||||
type OmitIndexSignature<ObjectType> = {
|
||||
[KeyType in keyof ObjectType
|
||||
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
||||
as {} extends Record<KeyType, unknown>
|
||||
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
||||
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
||||
]: ObjectType[KeyType];
|
||||
};
|
||||
```
|
||||
|
||||
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {OmitIndexSignature} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
// These index signatures will be removed.
|
||||
[x: string]: any
|
||||
[x: number]: any
|
||||
[x: symbol]: any
|
||||
[x: `head-${string}`]: string
|
||||
[x: `${string}-tail`]: string
|
||||
[x: `head-${string}-tail`]: string
|
||||
[x: `${bigint}`]: string
|
||||
[x: `embedded-${number}`]: string
|
||||
|
||||
// These explicitly defined keys will remain.
|
||||
foo: 'bar';
|
||||
qux?: 'baz';
|
||||
}
|
||||
|
||||
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
||||
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
||||
```
|
||||
|
||||
@see PickIndexSignature
|
||||
@category Object
|
||||
*/
|
||||
export type OmitIndexSignature<ObjectType> = {
|
||||
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
||||
? never
|
||||
: KeyType]: ObjectType[KeyType];
|
||||
};
|
1
node_modules/type-fest/source/opaque.d.ts
generated
vendored
Normal file
1
node_modules/type-fest/source/opaque.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './tagged';
|
39
node_modules/type-fest/source/optional-keys-of.d.ts
generated
vendored
Normal file
39
node_modules/type-fest/source/optional-keys-of.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
Extract all optional keys from the given type.
|
||||
|
||||
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {OptionalKeysOf, Except} from 'type-fest';
|
||||
|
||||
interface User {
|
||||
name: string;
|
||||
surname: string;
|
||||
|
||||
luckyNumber?: number;
|
||||
}
|
||||
|
||||
const REMOVE_FIELD = Symbol('remove field symbol');
|
||||
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
||||
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
||||
};
|
||||
|
||||
const update1: UpdateOperation<User> = {
|
||||
name: 'Alice'
|
||||
};
|
||||
|
||||
const update2: UpdateOperation<User> = {
|
||||
name: 'Bob',
|
||||
luckyNumber: REMOVE_FIELD
|
||||
};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type OptionalKeysOf<BaseType extends object> =
|
||||
BaseType extends unknown // For distributing `BaseType`
|
||||
? (keyof {
|
||||
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
||||
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
||||
: never; // Should never happen
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user