spectacles-ts icon indicating copy to clipboard operation
spectacles-ts copied to clipboard

Use with Redux toolkit - "Type instantiation is excessively deep and possibly infinite"

Open ssirowy opened this issue 2 years ago • 8 comments

🐛 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: Screen Shot 2022-04-03 at 2 36 43 PM

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

ssirowy avatar Apr 03 '22 21:04 ssirowy

thanks for this! Could you post the IGlassState type, or something equivalent?

A typescript playground would be great - something like this

anthonyjoeseph avatar Apr 04 '22 13:04 anthonyjoeseph

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 avatar Apr 05 '22 21:04 anthonyjoeseph

@anthonyjoeseph you might consider adding 4.5 as an optional peer dependency?

{
  "peerDependencies": { 
    "typescript": "> 4.5.0",
  },
  "peerDependenciesMeta": {
    "typescript": {
      "optional": true
    }
  }
}

ahrjarrett avatar Apr 07 '22 04:04 ahrjarrett

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

anthonyjoeseph avatar Apr 07 '22 12:04 anthonyjoeseph

Actually, looks like the Typescript team has a feature for this (sort of) using typeVersions. Going to make a PR

anthonyjoeseph avatar Apr 07 '22 12:04 anthonyjoeseph

@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 avatar Apr 17 '22 05:04 anthonyjoeseph

@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:

Typescrypt Playground

chrisfernandes102 avatar Jun 23 '22 19:06 chrisfernandes102

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

anthonyjoeseph avatar Sep 27 '22 15:09 anthonyjoeseph