question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeepMap error when spreading on `defaultValues`

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

To Reproduce

Go to sandbox.

View the defaultValues section – comment out the spreaded and uncomment the non spreaded… notice the typescript error difference

Codesandbox link (Required)

https://codesandbox.io/s/dry-violet-z0tpe

Expected behavior

Types inferred without DeepMap error on the overridden defaultValues

Screenshots

image

Additional context

RHF 6.9.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Oct 28, 2020

FYI @kotarella1110 I made the following change on DeepPartial.

-export type DeepPartial<T> = T extends Array<infer U>
-  ? Array<DeepPartial<U>>
-  : T extends ReadonlyArray<infer U>
-    ? ReadonlyArray<DeepPartial<U>>
-    : T extends Record<string, unknown>
-      ? {
-        [K in keyof T]?: DeepPartial<T[K]>;
-      }
-      : T;
+export type DeepPartial<T> = T extends Primitive
+  ? Partial<T>
+  : {
+      [P in keyof T]?: T[P] extends (infer U)[]
+        ? DeepPartial<U>[]
+        : T[P] extends Readonly<infer U>[]
+        ? Readonly<DeepPartial<U>>[]
+        : DeepPartial<T[P]>;
+    };

I think this issue is related as well: https://github.com/react-hook-form/react-hook-form/issues/3289

here is a CSB that was working correctly with the generic: https://codesandbox.io/s/pedantic-perlman-f93x8?file=/src/App.tsx:0-296 however I can spot the type is actually any, correct me if I am wrong, we will need to have the generic at useForm to fix those issues.

1reaction
bluebill1049commented, Oct 27, 2020

Yes I suppose that works by explicitly passing the generic, but I wonder if it can be inferred on the deep map?

Yes, @kotarella1110 is investigating a solution. worse case we will have to use with passing the generic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngrx- default values being overwritten through spread operator?
I was under the impression that the spread operator within a newly defined object would create a copy, but that appears to be...
Read more >
TS Support | React Hook Form - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
Lodash Documentation
Creates a new array concatenating array with any additional arrays and/or values. Since. 4.0.0. Arguments. array (Array): The array to concatenate ...
Read more >
Changelog - scssphp - GitHub Pages
Improve error messages for incorrect units in color functions (@stof) ... Add support for deep map manipulation in map-get , map-has-key and ...
Read more >
ESO Phase 3 Data Release Description - ESO.org
ated by considering the information on the instrument line spread function, ... The pipeline parameters for this recipe are set to their default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found