Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/type-fest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.7.0
Choose a base ref
...
head repository: sindresorhus/type-fest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.7.1
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Nov 8, 2023

  1. Fix typos

    sindresorhus committed Nov 8, 2023
    Copy the full SHA
    f31a21c View commit details

Commits on Nov 9, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9f47b11 View commit details
  2. 4.7.1

    sindresorhus committed Nov 9, 2023
    Copy the full SHA
    570e27f View commit details
Showing with 11 additions and 13 deletions.
  1. +1 −1 package.json
  2. +5 −5 source/partial-deep.d.ts
  3. +5 −4 source/pick-deep.d.ts
  4. +0 −3 test-d/partial-deep.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "type-fest",
"version": "4.7.0",
"version": "4.7.1",
"description": "A collection of essential TypeScript types",
"license": "(MIT OR CC0-1.0)",
"repository": "sindresorhus/type-fest",
10 changes: 5 additions & 5 deletions source/partial-deep.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {BuiltIns, UnknownRecord} from './internal';
import type {BuiltIns} from './internal';

/**
@see PartialDeep
@@ -69,17 +69,17 @@ export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
: T extends ReadonlySet<infer ItemType>
? PartialReadonlySetDeep<ItemType, Options>
: T extends UnknownRecord
? PartialObjectDeep<T, Options>
: T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
: 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
: T;
: PartialObjectDeep<T, Options>
: unknown;

/**
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
9 changes: 5 additions & 4 deletions source/pick-deep.d.ts
Original file line number Diff line number Diff line change
@@ -37,7 +37,8 @@ type Configuration = {
type NameConfig = PickDeep<Configuration, 'userConfig.name'>;
// type NameConfig = {
// userConfig: {
// name: string;
// name: string;
// }
// };
// Supports optional properties
@@ -50,7 +51,7 @@ type User = PickDeep<PartialDeep<Configuration>, 'userConfig.name' | 'userConfig
// };
// Supports array
type AddressConfig = PickDeep<Configuration, `userConfig.address.0`>;
type AddressConfig = PickDeep<Configuration, 'userConfig.address.0'>;
// type AddressConfig = {
// userConfig: {
// address: [{
@@ -61,8 +62,8 @@ type AddressConfig = PickDeep<Configuration, `userConfig.address.0`>;
// }
// Supports recurse into array
type Street = PickDeep<Configuration, `userConfig.address.1.street2`>;
// type AddressConfig = {
type Street = PickDeep<Configuration, 'userConfig.address.1.street2'>;
// type Street = {
// userConfig: {
// address: [
// unknown,
3 changes: 0 additions & 3 deletions test-d/partial-deep.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ const foo = {
bar: {
function: (_: string): void => undefined,
classConstructor: ClassA,
html: document.createElement('div'),
object: {key: 'value'},
string: 'waldo',
number: 1,
@@ -59,8 +58,6 @@ expectAssignable<ReadonlyMap<string | undefined, string | undefined> | undefined
expectAssignable<ReadonlySet<string | undefined> | undefined>(partialDeepFoo.bar!.readonlySet);
expectType<ReadonlyArray<string | undefined> | undefined>(partialDeepFoo.bar!.readonlyArray);
expectType<readonly ['foo'?] | undefined>(partialDeepFoo.bar!.readonlyTuple);
// Test for https://github.com/sindresorhus/type-fest/issues/651
expectType<HTMLDivElement | undefined>(partialDeepFoo.bar!.html);
// Check for compiling with omitting partial keys
partialDeepFoo = {baz: 'fred'};
partialDeepFoo = {bar: {string: 'waldo'}};