Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date to DeepPartial type helper #552

Closed
bombillazo opened this issue Feb 5, 2023 · 3 comments
Closed

Add Date to DeepPartial type helper #552

bombillazo opened this issue Feb 5, 2023 · 3 comments

Comments

@bombillazo
Copy link

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch type-fest@3.5.5 for the project I'm working on.

I added an additional check to be able to match objects with Date typed values.

Here is the diff that solved my problem:

diff --git a/node_modules/type-fest/source/partial-deep.d.ts b/node_modules/type-fest/source/partial-deep.d.ts
index bbb3605..c2dbd41 100644
--- a/node_modules/type-fest/source/partial-deep.d.ts
+++ b/node_modules/type-fest/source/partial-deep.d.ts
@@ -71,17 +71,19 @@ export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends
 					? 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;
+            : T extends Date // checks for Date
+              ? 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;
 
 /**
 Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.

This issue body was partially generated by patch-package.

@sindresorhus
Copy link
Owner

Date is already handled here:

export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns

export type BuiltIns = Primitive | Date | RegExp;

@bombillazo
Copy link
Author

Ooh, ok, maybe this was recent, Ive had this patch for months now for some reason was the only way to fix. ill confirm on my side, thanks!

@bombillazo
Copy link
Author

Seems like this patch indeed is no longer necessary, if anything creeps up I'll share, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants