Type inference issue with MomentJS
Hello! I discovered this library recently andI have been trying to see if it could fit our needs in our project. As I was testing for a date field with MUI and MomentJS, I started facing a "Type instantiation is excessively deep and possibly infinite" error from TypeScript.
Based on the FAQ, it seems it could by an issue on your side, so I made a small reproduction: https://codesandbox.io/p/devbox/confident-smoke-hyn4nl
It's also possible I'm doing something wrong, but then I don't know what ๐
Thanks a lot for your help!
10 Replies
deep-jadeโข3w ago
looks like the reproduction is having a hard time installing correctly. Could you give a small step-by-step description so I can test it myself?
afraid-scarletOPโข3w ago
Yes, I had issues having moment correctly included in the repro, not sure why...
So what I did was simply add an MUI date field to the form composition example and cleaned up to a minimal state.
deep-jadeโข3w ago
wait, yeah I can just copy the files and install whatever's imported
my initial hunch is that it's a recursive type that's causing it, but I'll confirm it first
afraid-scarletOPโข3w ago
Awesome thanks. Just check the versions for the packages, I made the repro based on these pinned versions because that's the ones we have in our project
deep-jadeโข3w ago
yup, as I thought. Here's the reproducible example:
didn't see recursive typing at first, but we currently don't have a stop condition for it
which means typescript tries to infer an infinite possibilities of form names
deep-jadeโข3w ago
Related issue: https://github.com/TanStack/form/issues/1553
GitHub
Recursive type, breaks the typesafety ยท Issue #1553 ยท TanStack/form
Describe the bug If I have an object, that can reference itself. It will break the type-safety of the form. For example here the list is any, and the function getFieldValue or the property name on ...
afraid-scarletOPโข3w ago
Ok, I see. Thank you!
Is there any known workaround for it?
deep-jadeโข3w ago
not that I know of, but reports were sparse so far. Momentjs is a pretty common library though, so feel free to leave a comment on the linked issue about it. I'll also bring it up to the group ๐
afraid-scarletOPโข3w ago
Alright, will do!
I will try to create a new repro that is not broken, if I can. Else I will put that one, better than nothing I guess
deep-jadeโข3w ago
DeepKeys is importable, so that one LOC I sent is already a reproducible example