type-fest
Advanced tools
Comparing version 2.19.0 to 3.0.0
154
index.d.ts
@@ -8,42 +8,49 @@ // Basic | ||
// Utilities | ||
export {Except} from './source/except'; | ||
export {Mutable} from './source/mutable'; | ||
export {Writable} from './source/writable'; | ||
export {Merge} from './source/merge'; | ||
export {MergeExclusive} from './source/merge-exclusive'; | ||
export {RequireAtLeastOne} from './source/require-at-least-one'; | ||
export {RequireExactlyOne} from './source/require-exactly-one'; | ||
export {RequireAllOrNone} from './source/require-all-or-none'; | ||
export {RemoveIndexSignature} from './source/remove-index-signature'; | ||
export {PartialDeep, PartialDeepOptions} from './source/partial-deep'; | ||
export {PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions} from './source/partial-on-undefined-deep'; | ||
export {ReadonlyDeep} from './source/readonly-deep'; | ||
export {LiteralUnion} from './source/literal-union'; | ||
export {Promisable} from './source/promisable'; | ||
export {Opaque, UnwrapOpaque} from './source/opaque'; | ||
export {InvariantOf} from './source/invariant-of'; | ||
export {SetOptional} from './source/set-optional'; | ||
export {SetRequired} from './source/set-required'; | ||
export {SetNonNullable} from './source/set-non-nullable'; | ||
export {ValueOf} from './source/value-of'; | ||
export {PromiseValue} from './source/promise-value'; | ||
export {AsyncReturnType} from './source/async-return-type'; | ||
export {ConditionalExcept} from './source/conditional-except'; | ||
export {ConditionalKeys} from './source/conditional-keys'; | ||
export {ConditionalPick} from './source/conditional-pick'; | ||
export {UnionToIntersection} from './source/union-to-intersection'; | ||
export {Stringified} from './source/stringified'; | ||
export {FixedLengthArray} from './source/fixed-length-array'; | ||
export {MultidimensionalArray} from './source/multidimensional-array'; | ||
export {MultidimensionalReadonlyArray} from './source/multidimensional-readonly-array'; | ||
export {IterableElement} from './source/iterable-element'; | ||
export {Entry} from './source/entry'; | ||
export {Entries} from './source/entries'; | ||
export {SetReturnType} from './source/set-return-type'; | ||
export {Asyncify} from './source/asyncify'; | ||
export {Simplify, SimplifyOptions} from './source/simplify'; | ||
export {Jsonify} from './source/jsonify'; | ||
export {Schema} from './source/schema'; | ||
export {LiteralToPrimitive} from './source/literal-to-primitive'; | ||
export { | ||
export type {EmptyObject, IsEmptyObject} from './source/empty-object'; | ||
export type {Except} from './source/except'; | ||
export type {Writable} from './source/writable'; | ||
export type {Merge} from './source/merge'; | ||
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 { | ||
OmitIndexSignature, | ||
/** | ||
@deprecated Renamed to {@link OmitIndexSignature}. | ||
*/ | ||
OmitIndexSignature as RemoveIndexSignature, | ||
} from './source/omit-index-signature'; | ||
export type {PickIndexSignature} from './source/pick-index-signature'; | ||
export type {PartialDeep, PartialDeepOptions} from './source/partial-deep'; | ||
export type {PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions} from './source/partial-on-undefined-deep'; | ||
export type {ReadonlyDeep} from './source/readonly-deep'; | ||
export type {LiteralUnion} from './source/literal-union'; | ||
export type {Promisable} from './source/promisable'; | ||
export type {Opaque, UnwrapOpaque} from './source/opaque'; | ||
export type {InvariantOf} from './source/invariant-of'; | ||
export type {SetOptional} from './source/set-optional'; | ||
export type {SetRequired} from './source/set-required'; | ||
export type {SetNonNullable} from './source/set-non-nullable'; | ||
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 {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 {Asyncify} from './source/asyncify'; | ||
export type {Simplify} from './source/simplify'; | ||
export type {Jsonify} from './source/jsonify'; | ||
export type {Schema} from './source/schema'; | ||
export type {LiteralToPrimitive} from './source/literal-to-primitive'; | ||
export type { | ||
PositiveInfinity, | ||
@@ -60,38 +67,39 @@ NegativeInfinity, | ||
} from './source/numeric'; | ||
export {StringKeyOf} from './source/string-key-of'; | ||
export {Exact} from './source/exact'; | ||
export {ReadonlyTuple} from './source/readonly-tuple'; | ||
export {OptionalKeysOf} from './source/optional-keys-of'; | ||
export {HasOptionalKeys} from './source/has-optional-keys'; | ||
export {RequiredKeysOf} from './source/required-keys-of'; | ||
export {HasRequiredKeys} from './source/has-required-keys'; | ||
export {Spread} from './source/spread'; | ||
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 {HasOptionalKeys} from './source/has-optional-keys'; | ||
export type {RequiredKeysOf} from './source/required-keys-of'; | ||
export type {HasRequiredKeys} from './source/has-required-keys'; | ||
export type {Spread} from './source/spread'; | ||
export type {TupleToUnion} from './source/tuple-to-union'; | ||
// Template literal types | ||
export {CamelCase} from './source/camel-case'; | ||
export {CamelCasedProperties} from './source/camel-cased-properties'; | ||
export {CamelCasedPropertiesDeep} from './source/camel-cased-properties-deep'; | ||
export {KebabCase} from './source/kebab-case'; | ||
export {KebabCasedProperties} from './source/kebab-cased-properties'; | ||
export {KebabCasedPropertiesDeep} from './source/kebab-cased-properties-deep'; | ||
export {PascalCase} from './source/pascal-case'; | ||
export {PascalCasedProperties} from './source/pascal-cased-properties'; | ||
export {PascalCasedPropertiesDeep} from './source/pascal-cased-properties-deep'; | ||
export {SnakeCase} from './source/snake-case'; | ||
export {SnakeCasedProperties} from './source/snake-cased-properties'; | ||
export {SnakeCasedPropertiesDeep} from './source/snake-cased-properties-deep'; | ||
export {ScreamingSnakeCase} from './source/screaming-snake-case'; | ||
export {DelimiterCase} from './source/delimiter-case'; | ||
export {DelimiterCasedProperties} from './source/delimiter-cased-properties'; | ||
export {DelimiterCasedPropertiesDeep} from './source/delimiter-cased-properties-deep'; | ||
export {Join} from './source/join'; | ||
export {Split} from './source/split'; | ||
export {Trim} from './source/trim'; | ||
export {Replace} from './source/replace'; | ||
export {Includes} from './source/includes'; | ||
export {Get} from './source/get'; | ||
export {LastArrayElement} from './source/last-array-element'; | ||
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 {Trim} from './source/trim'; | ||
export type {Replace} from './source/replace'; | ||
export type {Includes} from './source/includes'; | ||
export type {Get} from './source/get'; | ||
export type {LastArrayElement} from './source/last-array-element'; | ||
// Miscellaneous | ||
export {PackageJson} from './source/package-json'; | ||
export {TsConfigJson} from './source/tsconfig-json'; | ||
export type {PackageJson} from './source/package-json'; | ||
export type {TsConfigJson} from './source/tsconfig-json'; |
{ | ||
"name": "type-fest", | ||
"version": "2.19.0", | ||
"version": "3.0.0", | ||
"description": "A collection of essential TypeScript types", | ||
@@ -13,4 +13,5 @@ "license": "(MIT OR CC0-1.0)", | ||
}, | ||
"types": "./index.d.ts", | ||
"engines": { | ||
"node": ">=12.20" | ||
"node": ">=14.16" | ||
}, | ||
@@ -33,17 +34,17 @@ "scripts": { | ||
"merge", | ||
"json" | ||
"json", | ||
"generics" | ||
], | ||
"devDependencies": { | ||
"@sindresorhus/tsconfig": "~0.7.0", | ||
"expect-type": "^0.13.0", | ||
"tsd": "^0.20.0", | ||
"typescript": "^4.6.3", | ||
"xo": "^0.43.0" | ||
"expect-type": "^0.14.2", | ||
"tsd": "^0.24.1", | ||
"typescript": "^4.8.3", | ||
"xo": "^0.52.2" | ||
}, | ||
"types": "./index.d.ts", | ||
"xo": { | ||
"rules": { | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/indent": "off", | ||
"node/no-unsupported-features/es-builtins": "off", | ||
"@typescript-eslint/naming-convention": "off", | ||
"import/extensions": "off", | ||
@@ -50,0 +51,0 @@ "@typescript-eslint/no-redeclare": "off", |
@@ -71,2 +71,16 @@ <div align="center"> | ||
</a> | ||
<br> | ||
<br> | ||
<a href="https://sizzy.co/?utm_campaign=github_repo&utm_source=github&utm_medium=referral&utm_content=type-fest&utm_term=sindre"> | ||
<div> | ||
<img src="https://sindresorhus.com/assets/thanks/sizzy-logo.png" width="240" alt="Sizzy"> | ||
</div> | ||
<div> | ||
<sub> | ||
<b>Before Sizzy:</b> web development is stressing you out, responsive design is hard, you have an overwhelming amount of opened tabs & apps. | ||
<br> | ||
<b>After Sizzy:</b> all the tools you need in one place, responsive design is a breeze, no more context switching. | ||
</sub> | ||
</div> | ||
</a> | ||
</p> | ||
@@ -99,3 +113,3 @@ </div> | ||
*Requires TypeScript >=4.2* | ||
*Requires TypeScript >=4.7* | ||
@@ -130,4 +144,6 @@ ## Usage | ||
- [`EmptyObject`](source/empty-object.d.ts) - Represents a strictly empty plain object, the `{}` value. | ||
- [`IsEmptyObject`](source/empty-object.d.ts) - Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value. | ||
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys. This is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys). | ||
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from all or some of an object's keys. The inverse of `Readonly<T>`. Formerly named `Mutable`. | ||
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from all or some of an object's keys. The inverse of `Readonly<T>`. | ||
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type. | ||
@@ -138,3 +154,4 @@ - [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive keys. | ||
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys. | ||
- [`RemoveIndexSignature`](source/remove-index-signature.d.ts) - Create a type that only has explicitly defined properties, absent of any index signatures. | ||
- [`OmitIndexSignature`](source/omit-index-signature.d.ts) - Omit any index signatures from the given object type, leaving only explicitly defined properties. | ||
- [`PickIndexSignature`](source/pick-index-signature.d.ts) - Pick only index signatures from the given object type, leaving out all explicitly defined properties. | ||
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type. Use [`Partial<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) if you only need one level deep. | ||
@@ -153,2 +170,3 @@ - [`PartialOnUndefinedDeep`](source/partial-on-undefined-deep.d.ts) - Create a deep version of another type where all keys accepting `undefined` type are set to optional. | ||
- [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type. | ||
- [`ConditionalPickDeep`](source/conditional-pick-deep.d.ts) - Like `ConditionalPick` except that it selects the properties deeply. | ||
- [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type. | ||
@@ -202,2 +220,3 @@ - [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type. | ||
- [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length. | ||
- [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple into a union type of its elements. | ||
@@ -239,3 +258,3 @@ ### Numeric | ||
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). It also includes support for [TypeScript Declaration Files](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) and [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/). | ||
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 4.4). | ||
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). | ||
@@ -261,2 +280,3 @@ ## Declined types | ||
- `RecordDeep`- See [`Schema`](https://github.com/sindresorhus/type-fest/blob/main/source/schema.d.ts) | ||
- `Mutable`- See [`Writable`](https://github.com/sindresorhus/type-fest/blob/main/source/writable.d.ts) | ||
@@ -898,2 +918,3 @@ ## Tips | ||
- [Pelle Wessman](https://github.com/voxpelli) | ||
- [Sébastien Mischler](https://github.com/skarab42) | ||
@@ -903,13 +924,1 @@ ## License | ||
SPDX-License-Identifier: (MIT OR CC0-1.0) | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-type-fest?utm_source=npm-type-fest&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
@@ -1,3 +0,1 @@ | ||
import type {PromiseValue} from './promise-value'; | ||
type AsyncFunction = (...args: any[]) => Promise<unknown>; | ||
@@ -25,2 +23,2 @@ | ||
*/ | ||
export type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>; | ||
export type AsyncReturnType<Target extends AsyncFunction> = Awaited<ReturnType<Target>>; |
@@ -1,2 +0,1 @@ | ||
import type {PromiseValue} from './promise-value'; | ||
import type {SetReturnType} from './set-return-type'; | ||
@@ -33,2 +32,2 @@ | ||
*/ | ||
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<PromiseValue<ReturnType<Fn>>>>; | ||
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<Awaited<ReturnType<Fn>>>>; |
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
export type JsonObject = {[Key in string]?: JsonValue}; | ||
export type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined}; | ||
@@ -25,0 +25,0 @@ /** |
@@ -16,4 +16,4 @@ import type {WordSeparators} from '../source/internal'; | ||
: FirstPart extends '' | ||
? InnerCamelCaseStringArray<RemainingParts, PreviousPart> | ||
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}` | ||
? InnerCamelCaseStringArray<RemainingParts, PreviousPart> | ||
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}` | ||
: ''; | ||
@@ -20,0 +20,0 @@ |
@@ -50,6 +50,6 @@ import type {CamelCase} from './camel-case'; | ||
: Value extends Array<infer U> | ||
? Array<CamelCasedPropertiesDeep<U>> | ||
: Value extends Set<infer U> | ||
? Set<CamelCasedPropertiesDeep<U>> : { | ||
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>; | ||
}; | ||
? Array<CamelCasedPropertiesDeep<U>> | ||
: Value extends Set<infer U> | ||
? Set<CamelCasedPropertiesDeep<U>> : { | ||
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>; | ||
}; |
@@ -33,5 +33,5 @@ import type {CamelCase} from './camel-case'; | ||
: Value extends Array<infer U> | ||
? Value | ||
: { | ||
? Value | ||
: { | ||
[K in keyof Value as CamelCase<K>]: Value[K]; | ||
}; | ||
}; |
@@ -43,4 +43,4 @@ import type {Except} from './except'; | ||
export type ConditionalExcept<Base, Condition> = Except< | ||
Base, | ||
ConditionalKeys<Base, Condition> | ||
Base, | ||
ConditionalKeys<Base, Condition> | ||
>; |
@@ -34,15 +34,15 @@ /** | ||
export type ConditionalKeys<Base, Condition> = NonNullable< | ||
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union. | ||
{ | ||
// 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 since the condition passes. | ||
? Key | ||
// Discard this key since the condition fails. | ||
: never; | ||
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union. | ||
{ | ||
// 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 since the condition passes. | ||
? 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] | ||
}[keyof Base] | ||
>; |
@@ -42,4 +42,4 @@ import type {ConditionalKeys} from './conditional-keys'; | ||
export type ConditionalPick<Base, Condition> = Pick< | ||
Base, | ||
ConditionalKeys<Base, Condition> | ||
Base, | ||
ConditionalKeys<Base, Condition> | ||
>; |
import type {UpperCaseCharacters, WordSeparators} from '../source/internal'; | ||
// Transforms a string that is fully uppercase into a fully lowercase version. Needed to add support for SCREMAING_SNAKE_CASE, see https://github.com/sindresorhus/type-fest/issues/385 | ||
type UpperCaseToLowerCase<T extends string> = T extends Uppercase<T> ? Lowercase<T> : T; | ||
// This implemntation does not supports SCREMAING_SNAKE_CASE, it used internaly by `SplitIncludingDelimiters`. | ||
type SplitIncludingDelimiters_<Source extends string, Delimiter extends string> = | ||
Source extends '' ? [] : | ||
Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ? | ||
( | ||
Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}` | ||
? UsedDelimiter extends Delimiter | ||
? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}` | ||
? [...SplitIncludingDelimiters<FirstPart, Delimiter>, UsedDelimiter, ...SplitIncludingDelimiters<SecondPart, Delimiter>] | ||
: never | ||
: never | ||
: never | ||
) : | ||
[Source]; | ||
/** | ||
@@ -8,15 +26,3 @@ Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters. | ||
*/ | ||
export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> = | ||
Source extends '' ? [] : | ||
Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ? | ||
( | ||
Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}` | ||
? UsedDelimiter extends Delimiter | ||
? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}` | ||
? [...SplitIncludingDelimiters<FirstPart, Delimiter>, UsedDelimiter, ...SplitIncludingDelimiters<SecondPart, Delimiter>] | ||
: never | ||
: never | ||
: never | ||
) : | ||
[Source]; | ||
export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> = SplitIncludingDelimiters_<UpperCaseToLowerCase<Source>, Delimiter>; | ||
@@ -30,5 +36,5 @@ /** | ||
StringPart extends UsedWordSeparators ? Delimiter : | ||
Start extends true ? Lowercase<StringPart> : | ||
StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase<StringPart>}` : | ||
StringPart; | ||
Start extends true ? Lowercase<StringPart> : | ||
StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase<StringPart>}` : | ||
StringPart; | ||
@@ -46,4 +52,4 @@ /** | ||
: Parts extends [string] | ||
? string | ||
: ''; | ||
? string | ||
: ''; | ||
@@ -88,10 +94,10 @@ /** | ||
*/ | ||
export type DelimiterCase<Value, Delimiter extends string> = Value extends string | ||
export type DelimiterCase<Value, Delimiter extends string> = string extends Value ? Value : Value extends string | ||
? StringArrayToDelimiterCase< | ||
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>, | ||
true, | ||
WordSeparators, | ||
UpperCaseCharacters, | ||
Delimiter | ||
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>, | ||
true, | ||
WordSeparators, | ||
UpperCaseCharacters, | ||
Delimiter | ||
> | ||
: Value; |
@@ -53,9 +53,9 @@ import type {DelimiterCase} from './delimiter-case'; | ||
: Value extends Array<infer U> | ||
? Array<DelimiterCasedPropertiesDeep<U, Delimiter>> | ||
: Value extends Set<infer U> | ||
? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : { | ||
[K in keyof Value as DelimiterCase< | ||
? Array<DelimiterCasedPropertiesDeep<U, Delimiter>> | ||
: Value extends Set<infer U> | ||
? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : { | ||
[K in keyof Value as DelimiterCase< | ||
K, | ||
Delimiter | ||
>]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>; | ||
}; | ||
>]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>; | ||
}; |
@@ -36,3 +36,3 @@ import type {DelimiterCase} from './delimiter-case'; | ||
: Value extends Array<infer U> | ||
? Value | ||
: {[K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K]}; | ||
? Value | ||
: {[K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K]}; |
@@ -60,4 +60,4 @@ import type {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry'; | ||
: BaseType extends Set<unknown> ? SetEntries<BaseType> | ||
: BaseType extends readonly unknown[] ? ArrayEntries<BaseType> | ||
: BaseType extends object ? ObjectEntries<BaseType> | ||
: never; | ||
: BaseType extends readonly unknown[] ? ArrayEntries<BaseType> | ||
: BaseType extends object ? ObjectEntries<BaseType> | ||
: never; |
@@ -63,4 +63,4 @@ type MapKey<BaseType> = BaseType extends Map<infer KeyType, unknown> ? KeyType : never; | ||
: BaseType extends Set<unknown> ? SetEntry<BaseType> | ||
: BaseType extends readonly unknown[] ? ArrayEntry<BaseType> | ||
: BaseType extends object ? ObjectEntry<BaseType> | ||
: never; | ||
: BaseType extends readonly unknown[] ? ArrayEntry<BaseType> | ||
: BaseType extends object ? ObjectEntry<BaseType> | ||
: never; |
@@ -25,3 +25,3 @@ import type {KeysOfUnion} from './internal'; | ||
type ExactObject<ParameterType, InputType> = {[Key in keyof ParameterType]: Exact<ParameterType[Key], ObjectValue<InputType, Key>>} | ||
& Record<Exclude<keyof InputType, KeysOfUnion<ParameterType>>, never>; | ||
& Record<Exclude<keyof InputType, KeysOfUnion<ParameterType>>, never>; | ||
@@ -72,4 +72,4 @@ /** | ||
// In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray. | ||
: ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>> | ||
: ParameterType extends object ? ExactObject<ParameterType, InputType> | ||
: ParameterType; | ||
: ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>> | ||
: ParameterType extends object ? ExactObject<ParameterType, InputType> | ||
: ParameterType; |
@@ -37,4 +37,4 @@ /** | ||
export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick< | ||
ArrayPrototype, | ||
Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys> | ||
ArrayPrototype, | ||
Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys> | ||
> & { | ||
@@ -41,0 +41,0 @@ [index: number]: Element; |
@@ -6,2 +6,9 @@ import type {StringDigit} from '../source/internal'; | ||
type GetOptions = { | ||
/** | ||
Include `undefined` in the return type when accessing properties. | ||
Setting this to `false` is not recommended. | ||
@default true | ||
*/ | ||
strict?: boolean; | ||
@@ -15,10 +22,10 @@ }; | ||
Keys extends [] | ||
? BaseType | ||
: Keys extends readonly [infer Head, ...infer Tail] | ||
? GetWithPath< | ||
PropertyOf<BaseType, Extract<Head, string>, Options>, | ||
Extract<Tail, string[]>, | ||
Options | ||
> | ||
: never; | ||
? BaseType | ||
: Keys extends readonly [infer Head, ...infer Tail] | ||
? GetWithPath< | ||
PropertyOf<BaseType, Extract<Head, string>, Options>, | ||
Extract<Tail, string[]>, | ||
Options | ||
> | ||
: never; | ||
@@ -29,3 +36,3 @@ /** | ||
type Strictify<Type, Options extends GetOptions> = | ||
Options['strict'] extends true ? Type | undefined : Type; | ||
Options['strict'] extends false ? Type : (Type | undefined); | ||
@@ -40,6 +47,6 @@ /** | ||
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]; | ||
? 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]; | ||
@@ -65,8 +72,8 @@ /** | ||
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; | ||
? Tail extends `[${string}` | ||
? `${Head}.${FixPathSquareBrackets<Tail>}` | ||
: `${Head}${FixPathSquareBrackets<Tail>}` | ||
: Path extends `${infer Head}[${infer Middle}]${infer Tail}` | ||
? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}` | ||
: Path; | ||
@@ -86,6 +93,6 @@ /** | ||
LongString extends '' | ||
? true | ||
: LongString extends `${Substring}${infer Tail}` | ||
? ConsistsOnlyOf<Tail, Substring> | ||
: false; | ||
? true | ||
: LongString extends `${Substring}${infer Tail}` | ||
? ConsistsOnlyOf<Tail, Substring> | ||
: false; | ||
@@ -124,19 +131,19 @@ /** | ||
BaseType extends null | undefined | ||
? undefined | ||
: Key extends keyof BaseType | ||
? StrictPropertyOf<BaseType, Key, Options> | ||
: BaseType extends [] | [unknown, ...unknown[]] | ||
? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds. | ||
: 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; | ||
? undefined | ||
: Key extends keyof BaseType | ||
? StrictPropertyOf<BaseType, Key, Options> | ||
: BaseType extends [] | [unknown, ...unknown[]] | ||
? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds. | ||
: 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; | ||
@@ -174,3 +181,3 @@ // 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(apiResponse, 'hits.hits[0]._source.name'); | ||
//=> Array<{given: string[]; family: string}> | ||
//=> Array<{given: string[]; family: string}> | undefined | ||
@@ -180,7 +187,7 @@ // Path also supports a readonly array of strings | ||
get(apiResponse, ['hits','hits', '0', '_source', 'name'] as const); | ||
//=> Array<{given: string[]; family: string}> | ||
//=> Array<{given: string[]; family: string}> | undefined | ||
// Strict mode: | ||
Get<string[], '3', {strict: true}> //=> string | undefined | ||
Get<Record<string, string>, 'foo', {strict: true}> // => string | undefined | ||
// Non-strict mode: | ||
Get<string[], '3', {strict: false}> //=> string | ||
Get<Record<string, string>, 'foo', {strict: true}> // => string | ||
``` | ||
@@ -187,0 +194,0 @@ |
@@ -1,2 +0,2 @@ | ||
import {OptionalKeysOf} from './optional-keys-of'; | ||
import type {OptionalKeysOf} from './optional-keys-of'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import {RequiredKeysOf} from './required-keys-of'; | ||
import type {RequiredKeysOf} from './required-keys-of'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -51,5 +51,5 @@ /** | ||
TargetIterable extends Iterable<infer ElementType> ? | ||
ElementType : | ||
TargetIterable extends AsyncIterable<infer ElementType> ? | ||
ElementType : | ||
never; | ||
ElementType : | ||
TargetIterable extends AsyncIterable<infer ElementType> ? | ||
ElementType : | ||
never; |
@@ -29,3 +29,3 @@ /** | ||
// @ts-expect-error `Rest` is inferred as `unknown` here: https://github.com/microsoft/TypeScript/issues/45281 | ||
Strings extends [string | number, ...infer Rest] ? `${Strings[0]}${Delimiter}${Join<Rest, Delimiter>}` : | ||
string; | ||
Strings extends [string | number, ...infer Rest] ? `${Strings[0]}${Delimiter}${Join<Rest, Delimiter>}` : | ||
string; |
import type {JsonPrimitive, JsonValue} from './basic'; | ||
import {Finite, NegativeInfinity, PositiveInfinity} from './numeric'; | ||
import {TypedArray} from './typed-array'; | ||
import type {Merge} from './merge'; | ||
import type {NegativeInfinity, PositiveInfinity} from './numeric'; | ||
import type {TypedArray} from './typed-array'; | ||
@@ -8,2 +9,23 @@ // Note: The return value has to be `any` and not `unknown` so it can match `void`. | ||
// 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 | ||
: [(...args: any[]) => any] extends [Type[Key]] | ||
? never | ||
: Key; | ||
// Returns never if the key or property is not jsonable or optional otherwise return the key. | ||
type RequiredKeyFilter<Type, Key extends keyof Type> = undefined extends Type[Key] | ||
? never | ||
: BaseKeyFilter<Type, Key>; | ||
// Returns never if the key or property is not jsonable or required otherwise return the key. | ||
type OptionalKeyFilter<Type, Key extends keyof Type> = undefined extends Type[Key] | ||
? Type[Key] extends undefined | ||
? never | ||
: BaseKeyFilter<Type, Key> | ||
: never; | ||
/** | ||
@@ -66,3 +88,3 @@ Transform a type to one that is assignable to the `JsonValue` type. | ||
*/ | ||
type Jsonify<T> = | ||
export type Jsonify<T> = | ||
// Check if there are any non-JSONable types represented in the union. | ||
@@ -74,20 +96,20 @@ // Note: The use of tuples in this first condition side-steps distributive conditional types | ||
: T extends JsonPrimitive ? T // Primitive is acceptable | ||
: T extends object | ||
: T extends object | ||
// 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 | ||
: never // Not Jsonable because its toJSON() method does not return JsonValue | ||
// Instanced primitives are objects | ||
: T extends Number ? number | ||
: T extends String ? string | ||
: T extends Boolean ? boolean | ||
: T extends Map<any, any> | Set<any> ? {} | ||
: T extends TypedArray ? Record<string, number> | ||
: T extends any[] | ||
? {[I in keyof T]: T[I] extends NotJsonable ? null : Jsonify<T[I]>} | ||
: {[P in keyof T as P extends symbol ? never | ||
: T[P] extends NotJsonable ? never | ||
: P | ||
]: Jsonify<Required<T>[P]>} // Recursive call for its children | ||
: never // Otherwise any other non-object is removed | ||
? T extends {toJSON(): infer J} ? (() => J) extends (() => JsonValue) // Is J assignable to JsonValue? | ||
? J // Then T is Jsonable and its Jsonable value is J | ||
: never // Not Jsonable because its toJSON() method does not return JsonValue | ||
// Instanced primitives are objects | ||
: T extends Number ? number | ||
: T extends String ? string | ||
: T extends Boolean ? boolean | ||
: T extends Map<any, any> | Set<any> ? {} | ||
: T extends TypedArray ? Record<string, number> | ||
: T extends any[] | ||
? {[I in keyof T]: T[I] extends NotJsonable ? null : Jsonify<T[I]>} | ||
: Merge< | ||
{[Key in keyof T as RequiredKeyFilter<T, Key>]: Jsonify<T[Key]>}, | ||
{[Key in keyof T as OptionalKeyFilter<T, Key>]?: Jsonify<Exclude<T[Key], undefined>>} | ||
> // Recursive call for its children | ||
: never // Otherwise any other non-object is removed | ||
: never; // Otherwise non-JSONable type union was found not empty |
@@ -25,5 +25,5 @@ /** | ||
: ValueType extends readonly [infer _, ...infer Tail] | ||
? LastArrayElement<Tail> | ||
: ValueType extends ReadonlyArray<infer ElementType> | ||
? ElementType | ||
: never; | ||
? LastArrayElement<Tail> | ||
: ValueType extends ReadonlyArray<infer ElementType> | ||
? ElementType | ||
: never; |
@@ -25,13 +25,13 @@ /** | ||
: 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; | ||
? bigint | ||
: T extends string | ||
? string | ||
: T extends boolean | ||
? boolean | ||
: T extends symbol | ||
? symbol | ||
: T extends null | ||
? null | ||
: T extends undefined | ||
? undefined | ||
: never; |
@@ -1,5 +0,13 @@ | ||
import type {Except} from './except'; | ||
import type {Simplify} from './simplify'; | ||
import type {OmitIndexSignature} from './omit-index-signature'; | ||
import type {PickIndexSignature} from './pick-index-signature'; | ||
import type {EnforceOptional} from './enforce-optional'; | ||
type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType; | ||
// Merges two objects without worrying about index signatures or optional keys. | ||
type SimpleMerge<Destination, Source> = { | ||
[Key in keyof Destination | keyof Source]: Key extends keyof Source | ||
? Source[Key] | ||
: Key extends keyof Destination | ||
? Destination[Key] | ||
: never; | ||
}; | ||
@@ -13,12 +21,25 @@ /** | ||
type Foo = { | ||
a: number; | ||
b: string; | ||
}; | ||
interface Foo { | ||
[x: string]: unknown; | ||
[x: number]: unknown; | ||
foo: string; | ||
bar: symbol; | ||
} | ||
type Bar = { | ||
b: number; | ||
[x: number]: number; | ||
[x: symbol]: unknown; | ||
bar: Date; | ||
baz: boolean; | ||
}; | ||
const ab: Merge<Foo, Bar> = {a: 1, b: 2}; | ||
export type FooBar = Merge<Foo, Bar>; | ||
// => { | ||
// [x: string]: unknown; | ||
// [x: number]: number; | ||
// [x: symbol]: unknown; | ||
// foo: string; | ||
// bar: Date; | ||
// baz: boolean; | ||
// } | ||
``` | ||
@@ -28,2 +49,4 @@ | ||
*/ | ||
export type Merge<FirstType, SecondType> = Simplify<Merge_<FirstType, SecondType>>; | ||
export type Merge<Destination, Source> = EnforceOptional< | ||
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> | ||
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>; |
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 { | ||
@@ -59,5 +60,5 @@ readonly observable: symbol; | ||
*/ | ||
export interface ObservableLike<ValueType = unknown> { | ||
export type ObservableLike<ValueType = unknown> = { | ||
subscribe(observer?: Partial<Observer<ValueType>>): Unsubscribable; | ||
[Symbol.observable](): ObservableLike<ValueType>; | ||
} | ||
}; |
import type {LiteralUnion} from './literal-union'; | ||
import type {JsonObject, JsonValue} from './basic'; | ||
@@ -29,4 +30,4 @@ declare namespace PackageJson { | ||
export interface DirectoryLocations { | ||
[directoryType: string]: unknown; | ||
export type DirectoryLocations = { | ||
[directoryType: string]: JsonValue | undefined; | ||
@@ -62,3 +63,3 @@ /** | ||
test?: string; | ||
} | ||
}; | ||
@@ -216,12 +217,12 @@ export type Scripts = { | ||
export type ExportCondition = LiteralUnion< | ||
| 'import' | ||
| 'require' | ||
| 'node' | ||
| 'node-addons' | ||
| 'deno' | ||
| 'browser' | ||
| 'electron' | ||
| 'react-native' | ||
| 'default', | ||
string | ||
| 'import' | ||
| 'require' | ||
| 'node' | ||
| 'node-addons' | ||
| 'deno' | ||
| 'browser' | ||
| 'electron' | ||
| 'react-native' | ||
| 'default', | ||
string | ||
>; | ||
@@ -239,3 +240,3 @@ | ||
| ExportConditions | ||
| {[path: string]: Exports}; // eslint-disable-line @typescript-eslint/consistent-indexed-object-style | ||
| {[path: string]: Exports}; | ||
@@ -249,2 +250,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface NonStandardEntryPoints { | ||
@@ -282,3 +284,3 @@ /** | ||
export interface TypeScriptConfiguration { | ||
export type TypeScriptConfiguration = { | ||
/** | ||
@@ -298,3 +300,3 @@ Location of the bundled TypeScript declaration file. | ||
typings?: string; | ||
} | ||
}; | ||
@@ -304,3 +306,3 @@ /** | ||
*/ | ||
export interface WorkspaceConfig { | ||
export type WorkspaceConfig = { | ||
/** | ||
@@ -317,3 +319,3 @@ An array of workspace pattern strings which contain the workspace packages. | ||
nohoist?: WorkspacePattern[]; | ||
} | ||
}; | ||
@@ -331,3 +333,3 @@ /** | ||
export interface YarnConfiguration { | ||
export type YarnConfiguration = { | ||
/** | ||
@@ -353,5 +355,5 @@ Used to configure [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/). | ||
resolutions?: Dependency; | ||
} | ||
}; | ||
export interface JSPMConfiguration { | ||
export type JSPMConfiguration = { | ||
/** | ||
@@ -361,3 +363,3 @@ JSPM configuration. | ||
jspm?: PackageJson; | ||
} | ||
}; | ||
@@ -367,2 +369,3 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface PackageJsonStandard { | ||
@@ -497,3 +500,3 @@ /** | ||
*/ | ||
config?: Record<string, unknown>; | ||
config?: JsonObject; | ||
@@ -539,3 +542,3 @@ /** | ||
engines?: { | ||
[EngineName in 'npm' | 'node' | string]?: string; | ||
[EngineName in 'npm' | 'node' | string]?: string; // eslint-disable-line @typescript-eslint/no-redundant-type-constituents | ||
}; | ||
@@ -641,7 +644,26 @@ | ||
export interface PublishConfig { | ||
/** | ||
Type for [`package.json` file used by the Node.js runtime](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions). | ||
*/ | ||
export type NodeJsStandard = { | ||
/** | ||
Defines which package manager is expected to be used when working on the current project. It can set to any of the [supported package managers](https://nodejs.org/api/corepack.html#supported-package-managers), and will ensure that your teams use the exact same package manager versions without having to install anything else than Node.js. | ||
__This field is currently experimental and needs to be opted-in; check the [Corepack](https://nodejs.org/api/corepack.html) page for details about the procedure.__ | ||
@example | ||
```json | ||
{ | ||
"packageManager": "<package manager name>@<version>" | ||
} | ||
``` | ||
*/ | ||
packageManager?: string; | ||
}; | ||
export type PublishConfig = { | ||
/** | ||
Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig). | ||
*/ | ||
[additionalProperties: string]: unknown; | ||
[additionalProperties: string]: JsonValue | undefined; | ||
@@ -666,3 +688,3 @@ /** | ||
tag?: string; | ||
} | ||
}; | ||
} | ||
@@ -676,2 +698,4 @@ | ||
export type PackageJson = | ||
JsonObject & | ||
PackageJson.NodeJsStandard & | ||
PackageJson.PackageJsonStandard & | ||
@@ -678,0 +702,0 @@ PackageJson.NonStandardEntryPoints & |
@@ -6,10 +6,10 @@ import type {BuiltIns} from './internal'; | ||
*/ | ||
export interface PartialDeepOptions { | ||
export type PartialDeepOptions = { | ||
/** | ||
Whether to affect the individual elements of arrays and tuples. | ||
@default true | ||
@default false | ||
*/ | ||
readonly recurseIntoArrays?: boolean; | ||
} | ||
}; | ||
@@ -44,3 +44,3 @@ /** | ||
By default, this also affects array and tuple types: | ||
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument: | ||
@@ -54,3 +54,3 @@ ``` | ||
const partialSettings: PartialDeep<Settings> = { | ||
const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = { | ||
languages: [undefined] | ||
@@ -60,4 +60,2 @@ }; | ||
If this is undesirable, you can pass `{recurseIntoArrays: false}` as the second type argument. | ||
@category Object | ||
@@ -71,22 +69,22 @@ @category Array | ||
: T extends Map<infer KeyType, infer ValueType> | ||
? PartialMapDeep<KeyType, ValueType, Options> | ||
: T extends Set<infer ItemType> | ||
? PartialSetDeep<ItemType, Options> | ||
: T extends ReadonlyMap<infer KeyType, infer ValueType> | ||
? PartialReadonlyMapDeep<KeyType, ValueType, Options> | ||
: T extends ReadonlySet<infer ItemType> | ||
? PartialReadonlySetDeep<ItemType, Options> | ||
: T extends ((...arguments: any[]) => unknown) | ||
? T | undefined | ||
: T extends object | ||
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156 | ||
? Options['recurseIntoArrays'] extends false // If they opt out of array testing, just use the original type | ||
? T | ||
: ItemType[] extends T // Test for arrays (non-tuples) specifically | ||
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays | ||
? ReadonlyArray<PartialDeep<ItemType | undefined, Options>> | ||
: Array<PartialDeep<ItemType | undefined, Options>> | ||
: PartialObjectDeep<T, Options> // Tuples behave properly | ||
: PartialObjectDeep<T, Options> | ||
: unknown; | ||
? PartialMapDeep<KeyType, ValueType, Options> | ||
: T extends Set<infer ItemType> | ||
? PartialSetDeep<ItemType, Options> | ||
: T extends ReadonlyMap<infer KeyType, infer ValueType> | ||
? PartialReadonlyMapDeep<KeyType, ValueType, Options> | ||
: T extends ReadonlySet<infer ItemType> | ||
? PartialReadonlySetDeep<ItemType, Options> | ||
: T extends ((...arguments: any[]) => unknown) | ||
? T | undefined | ||
: T extends object | ||
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156 | ||
? Options['recurseIntoArrays'] extends true | ||
? ItemType[] extends T // Test for arrays (non-tuples) specifically | ||
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays | ||
? ReadonlyArray<PartialDeep<ItemType | undefined, Options>> | ||
: Array<PartialDeep<ItemType | undefined, Options>> | ||
: PartialObjectDeep<T, Options> // Tuples behave properly | ||
: T // If they don't opt into array testing, just use the original type | ||
: PartialObjectDeep<T, Options> | ||
: unknown; | ||
@@ -96,3 +94,3 @@ /** | ||
*/ | ||
interface PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> extends Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>> {} | ||
type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>; | ||
@@ -102,3 +100,3 @@ /** | ||
*/ | ||
interface PartialSetDeep<T, Options extends PartialDeepOptions> extends Set<PartialDeep<T, Options>> {} | ||
type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>; | ||
@@ -108,3 +106,3 @@ /** | ||
*/ | ||
interface PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> extends ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>> {} | ||
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>; | ||
@@ -114,3 +112,3 @@ /** | ||
*/ | ||
interface PartialReadonlySetDeep<T, Options extends PartialDeepOptions> extends ReadonlySet<PartialDeep<T, Options>> {} | ||
type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>; | ||
@@ -117,0 +115,0 @@ /** |
@@ -7,3 +7,3 @@ import type {BuiltIns} from './internal'; | ||
*/ | ||
export interface PartialOnUndefinedDeepOptions { | ||
export type PartialOnUndefinedDeepOptions = { | ||
/** | ||
@@ -15,3 +15,3 @@ Whether to affect the individual elements of arrays and tuples. | ||
readonly recurseIntoArrays?: boolean; | ||
} | ||
}; | ||
@@ -63,11 +63,11 @@ /** | ||
: T extends ReadonlyArray<infer U> // Test if type is array or tuple | ||
? Options['recurseIntoArrays'] extends true // Check if option is activated | ||
? U[] extends T // Check if array not tuple | ||
? readonly U[] extends T | ||
? ReadonlyArray<PartialOnUndefinedDeep<U, Options>> // Readonly array treatment | ||
: Array<PartialOnUndefinedDeep<U, Options>> // Mutable array treatment | ||
: PartialOnUndefinedDeep<{[Key in keyof T]: PartialOnUndefinedDeep<T[Key], Options>}, Options> // Tuple treatment | ||
: T | ||
: T extends Record<any, any> | undefined | ||
? PartialOnUndefinedDeep<T, Options> | ||
: unknown; | ||
? Options['recurseIntoArrays'] extends true // Check if option is activated | ||
? U[] extends T // Check if array not tuple | ||
? readonly U[] extends T | ||
? ReadonlyArray<PartialOnUndefinedDeep<U, Options>> // Readonly array treatment | ||
: Array<PartialOnUndefinedDeep<U, Options>> // Mutable array treatment | ||
: PartialOnUndefinedDeep<{[Key in keyof T]: PartialOnUndefinedDeep<T[Key], Options>}, Options> // Tuple treatment | ||
: T | ||
: T extends Record<any, any> | undefined | ||
? PartialOnUndefinedDeep<T, Options> | ||
: unknown; |
@@ -50,6 +50,6 @@ import type {PascalCase} from './pascal-case'; | ||
: Value extends Array<infer U> | ||
? Array<PascalCasedPropertiesDeep<U>> | ||
: Value extends Set<infer U> | ||
? Set<PascalCasedPropertiesDeep<U>> : { | ||
[K in keyof Value as PascalCase<K>]: PascalCasedPropertiesDeep<Value[K]>; | ||
}; | ||
? Array<PascalCasedPropertiesDeep<U>> | ||
: Value extends Set<infer U> | ||
? Set<PascalCasedPropertiesDeep<U>> : { | ||
[K in keyof Value as PascalCase<K>]: PascalCasedPropertiesDeep<Value[K]>; | ||
}; |
@@ -33,3 +33,3 @@ import type {PascalCase} from './pascal-case'; | ||
: Value extends Array<infer U> | ||
? Value | ||
: {[K in keyof Value as PascalCase<K>]: Value[K]}; | ||
? Value | ||
: {[K in keyof Value as PascalCase<K>]: Value[K]}; |
@@ -40,14 +40,14 @@ import type {BuiltIns} from './internal'; | ||
: T extends (...arguments: any[]) => unknown | ||
? {} extends ReadonlyObjectDeep<T> | ||
? T | ||
: HasMultipleCallSignatures<T> extends true | ||
? T | ||
: ((...arguments: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T> | ||
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>> | ||
? ReadonlyMapDeep<KeyType, ValueType> | ||
: T extends Readonly<ReadonlySet<infer ItemType>> | ||
? ReadonlySetDeep<ItemType> | ||
: T extends object | ||
? ReadonlyObjectDeep<T> | ||
: unknown; | ||
? {} extends ReadonlyObjectDeep<T> | ||
? T | ||
: HasMultipleCallSignatures<T> extends true | ||
? T | ||
: ((...arguments: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T> | ||
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>> | ||
? ReadonlyMapDeep<KeyType, ValueType> | ||
: T extends Readonly<ReadonlySet<infer ItemType>> | ||
? ReadonlySetDeep<ItemType> | ||
: T extends object | ||
? ReadonlyObjectDeep<T> | ||
: unknown; | ||
@@ -57,4 +57,3 @@ /** | ||
*/ | ||
interface ReadonlyMapDeep<KeyType, ValueType> | ||
extends Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>> {} | ||
type ReadonlyMapDeep<KeyType, ValueType> = {} & Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>>; | ||
@@ -64,4 +63,3 @@ /** | ||
*/ | ||
interface ReadonlySetDeep<ItemType> | ||
extends Readonly<ReadonlySet<ReadonlyDeep<ItemType>>> {} | ||
type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType>>>; | ||
@@ -68,0 +66,0 @@ /** |
@@ -36,2 +36,2 @@ /** | ||
) & | ||
Omit<ObjectType, KeysType>; // The rest of the keys. | ||
Omit<ObjectType, KeysType>; // The rest of the keys. |
@@ -31,6 +31,6 @@ import type {Except} from './except'; | ||
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & // 1. Make `Key`'s type required | ||
// 2. Make all other keys in `KeysType` optional | ||
Partial<Pick<ObjectType, Exclude<KeysType, Key>>>; | ||
// 2. Make all other keys in `KeysType` optional | ||
Partial<Pick<ObjectType, Exclude<KeysType, Key>>>; | ||
}[KeysType] & | ||
// 3. Add the remaining keys not in `KeysType` | ||
Except<ObjectType, KeysType>; | ||
// 3. Add the remaining keys not in `KeysType` | ||
Except<ObjectType, KeysType>; |
@@ -44,24 +44,24 @@ /** | ||
: ObjectType extends Map<unknown, unknown> | ||
? ValueType | ||
: ObjectType extends Set<unknown> | ||
? ValueType | ||
: ObjectType extends ReadonlyMap<unknown, unknown> | ||
? ValueType | ||
: ObjectType extends ReadonlySet<unknown> | ||
? ValueType | ||
: ObjectType extends readonly unknown[] | ||
? ValueType | ||
: ObjectType extends unknown[] | ||
? ValueType | ||
: ObjectType extends (...arguments: unknown[]) => unknown | ||
? ValueType | ||
: ObjectType extends Date | ||
? ValueType | ||
: ObjectType extends Function | ||
? ValueType | ||
: ObjectType extends RegExp | ||
? ValueType | ||
: ObjectType extends object | ||
? SchemaObject<ObjectType, ValueType> | ||
: ValueType; | ||
? ValueType | ||
: ObjectType extends Set<unknown> | ||
? ValueType | ||
: ObjectType extends ReadonlyMap<unknown, unknown> | ||
? ValueType | ||
: ObjectType extends ReadonlySet<unknown> | ||
? ValueType | ||
: ObjectType extends readonly unknown[] | ||
? ValueType | ||
: ObjectType extends unknown[] | ||
? ValueType | ||
: ObjectType extends (...arguments: unknown[]) => unknown | ||
? ValueType | ||
: ObjectType extends Date | ||
? ValueType | ||
: ObjectType extends Function | ||
? ValueType | ||
: ObjectType extends RegExp | ||
? ValueType | ||
: ObjectType extends object | ||
? SchemaObject<ObjectType, ValueType> | ||
: ValueType; | ||
@@ -68,0 +68,0 @@ /** |
@@ -31,6 +31,6 @@ import type {Except} from './except'; | ||
Simplify< | ||
// Pick just the keys that are readonly from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be non-nullable from the base type and make them non-nullable. | ||
{[Key in Keys]: NonNullable<BaseType[Key]>} | ||
// Pick just the keys that are readonly from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be non-nullable from the base type and make them non-nullable. | ||
{[Key in Keys]: NonNullable<BaseType[Key]>} | ||
>; |
@@ -31,6 +31,6 @@ import type {Except} from './except'; | ||
Simplify< | ||
// Pick just the keys that are readonly from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be mutable from the base type and make them mutable. | ||
Partial<Pick<BaseType, Keys>> | ||
// Pick just the keys that are readonly from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be mutable from the base type and make them mutable. | ||
Partial<Pick<BaseType, Keys>> | ||
>; |
@@ -31,6 +31,6 @@ import type {Except} from './except'; | ||
Simplify< | ||
// Pick just the keys that are optional from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be required from the base type and make them required. | ||
Required<Pick<BaseType, Keys>> | ||
// Pick just the keys that are optional from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be required from the base type and make them required. | ||
Required<Pick<BaseType, Keys>> | ||
>; |
/** | ||
@see Simplify | ||
*/ | ||
export interface SimplifyOptions { | ||
/** | ||
Do the simplification recursively. | ||
@default false | ||
*/ | ||
deep?: boolean; | ||
} | ||
// Flatten a type without worrying about the result. | ||
type Flatten< | ||
AnyType, | ||
Options extends SimplifyOptions = {}, | ||
> = Options['deep'] extends true | ||
? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>} | ||
: {[KeyType in keyof AnyType]: AnyType[KeyType]}; | ||
/** | ||
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability. | ||
@@ -78,7 +58,2 @@ | ||
*/ | ||
export type Simplify< | ||
AnyType, | ||
Options extends SimplifyOptions = {}, | ||
> = Flatten<AnyType> extends AnyType | ||
? Flatten<AnyType, Options> | ||
: AnyType; | ||
export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]}; |
@@ -28,3 +28,3 @@ /** | ||
: S extends Delimiter | ||
? [] | ||
: [S]; | ||
? [] | ||
: [S]; |
@@ -10,4 +10,4 @@ import type {Except} from './except'; | ||
} & Pick< | ||
SecondType, | ||
RequiredKeysOf<SecondType> | Exclude<keyof SecondType, keyof FirstType> | ||
SecondType, | ||
RequiredKeysOf<SecondType> | Exclude<keyof SecondType, keyof FirstType> | ||
>; | ||
@@ -80,4 +80,4 @@ | ||
export type Spread< | ||
FirstType extends Spreadable, | ||
SecondType extends Spreadable, | ||
FirstType extends Spreadable, | ||
SecondType extends Spreadable, | ||
> = FirstType extends TupleOrArray | ||
@@ -84,0 +84,0 @@ ? SecondType extends TupleOrArray |
@@ -20,2 +20,4 @@ declare namespace TsConfigJson { | ||
| 'ESNext' | ||
| 'Node16' | ||
| 'NodeNext' | ||
| 'None' | ||
@@ -32,2 +34,4 @@ // Lowercase alternatives | ||
| 'esnext' | ||
| 'node16' | ||
| 'nodenext' | ||
| 'none'; | ||
@@ -186,3 +190,3 @@ | ||
export interface Plugin { | ||
export type Plugin = { | ||
[key: string]: unknown; | ||
@@ -193,3 +197,3 @@ /** | ||
name?: string; | ||
} | ||
}; | ||
@@ -226,3 +230,3 @@ export type ImportsNotUsedAsValues = | ||
export interface CompilerOptions { | ||
export type CompilerOptions = { | ||
/** | ||
@@ -1001,3 +1005,3 @@ The character set of the input files. | ||
explainFiles?: boolean; | ||
} | ||
}; | ||
@@ -1026,3 +1030,3 @@ namespace WatchOptions { | ||
export interface WatchOptions { | ||
export type WatchOptions = { | ||
@@ -1068,3 +1072,3 @@ /** | ||
excludeFiles?: string[]; | ||
} | ||
}; | ||
@@ -1076,3 +1080,3 @@ /** | ||
*/ | ||
export interface TypeAcquisition { | ||
export type TypeAcquisition = { | ||
/** | ||
@@ -1092,5 +1096,5 @@ Enable auto type acquisition. | ||
exclude?: string[]; | ||
} | ||
}; | ||
export interface References { | ||
export type References = { | ||
/** | ||
@@ -1117,3 +1121,3 @@ A normalized path on disk. | ||
circular?: boolean; | ||
} | ||
}; | ||
} | ||
@@ -1126,3 +1130,3 @@ | ||
*/ | ||
export interface TsConfigJson { | ||
export type TsConfigJson = { | ||
/** | ||
@@ -1184,2 +1188,2 @@ Instructs the TypeScript compiler how to compile `.ts` files. | ||
references?: TsConfigJson.References[]; | ||
} | ||
}; |
@@ -58,4 +58,4 @@ /** | ||
// arguments of unions of functions as an intersection of the union. | ||
) extends ((mergedIntersection: infer Intersection) => void) | ||
? Intersection | ||
: never; | ||
) extends ((mergedIntersection: infer Intersection) => void) | ||
? Intersection | ||
: never; |
@@ -36,6 +36,6 @@ import type {Except} from './except'; | ||
Simplify< | ||
// Pick just the keys that are not writable from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key. | ||
{-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]} | ||
// Pick just the keys that are not writable from the base type. | ||
Except<BaseType, Keys> & | ||
// Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key. | ||
{-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]} | ||
>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
216154
85
4918
915