spectacles-ts
spectacles-ts copied to clipboard
Use with Redux toolkit - "Type instantiation is excessively deep and possibly infinite"
🐛 Potential Bug report
I recently pulled down spectacles-ts
into a React/Redux-based application as an alternative to using lodash's get
for pulling data from a Redux store.
Unfortunately, I hit a barrier pretty quickly in receiving a "Type instantiation is excessively deep and possibly infinite" error.
My Redux state type is generated using this approach from the Redux toolkit's documentation.
Without getting into details of our Redux store, the structure is fairly flat, with about 9-10 slices defined generated using the Redux toolkit library.
Here is a screenshot of the error:
I am in general just curious if this error has come up before and If this library is expected to work on more complex objects shown in the examples. Would love to give this library use, but stumbled pretty quickly, and any potential ideas on how I can solve would be greatly appreciated. Thanks!
Your environment
Software | Version(s) |
---|---|
spectacles-ts | 1.0.3 |
fp-ts | 2.11.8 |
TypeScript | 4.4.3 |
react | 17.0.2 |
redux | 4.1.1 |
redux-toolkit | 1.6.2 |
thanks for this! Could you post the IGlassState
type, or something equivalent?
A typescript playground would be great - something like this
I've just released a new version of spectacles (1.0.6) with some type optimizations that should help
Also, I noticed that you're using typescript version 4.4.3. Spectacles relies heavily on tail-recursion, which was optimized in typescript v 4.5. If it's possible to upgrade, that might help
@anthonyjoeseph you might consider adding 4.5 as an optional peer dependency?
{
"peerDependencies": {
"typescript": "> 4.5.0",
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
}
Thanks for the suggestion! As per the yarn docs
Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package
They refer to "dependencies", not "devDependencies". Typescript is a "devDependency". Unfortunately, I don't think there is a "peerDevDependencies"
I will however add it to the README. I'm actively investigating how spectacles-ts behaves on lower versions of typescript as well
Actually, looks like the Typescript team has a feature for this (sort of) using typeVersions. Going to make a PR
@ssirowy Closing if lieu of a repro. If you're able to make one, please feel free to post it and we can re-open the issue
Thanks for supporting the library!
@anthonyjoeseph I work with @ssirowy and was looking into this issue. I attempted to update to the latest typescript version but am running into the same problem. I made a TS playground for you here:
Hey @chrisfernandes102 ! sorry for the very late reply. Are you still getting this error locally? I'm not seeing it on my desktop machine. It could just be an issue w/ the typescript playground system - sometimes imports get a bit messed up. For example, fp-ts HKT doesn't work in playgrounds