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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type instantiation is excessively deep and possibly infinite #534

Closed
2 tasks done
dargmuesli opened this issue Apr 27, 2023 · 10 comments
Closed
2 tasks done

Type instantiation is excessively deep and possibly infinite #534

dargmuesli opened this issue Apr 27, 2023 · 10 comments
Labels
waiting for feedback The OP is asked for feedback or a proposal

Comments

@dargmuesli
Copy link

dargmuesli commented Apr 27, 2023

What happened?

Updated from v4.14.1 to v4.14.2: maevsi/maevsi#1215
Now there seems to be a loop in the typescript types:
image

Version

4.14.2

Runtime

Node.js

Runtime Details

typescript 5.0.4

Code to reproduce

https://github.com/maevsi/maevsi/actions/runs/4817158729/jobs/8577533577?pr=1215#step:7:1785

Required

  • I have searched the issues tracker and discussions for similar topics and couldn't find anything related.
  • I agree to follow this project's Code of Conduct
@panva
Copy link
Owner

panva commented Apr 27, 2023

Please provide a minimal reproduction example, a simple TS project that exhibits this issue with clear npm-based install and build steps.

You should narrow the types of the payload properties you access or at the very least type assert them.

@panva panva added the waiting for feedback The OP is asked for feedback or a proposal label Apr 27, 2023
@panva
Copy link
Owner

panva commented Apr 27, 2023

I'll revert for now but please do come back with the reproduction.

@panva panva removed the triage label Apr 27, 2023
github-actions bot pushed a commit that referenced this issue Apr 27, 2023
@dargmuesli
Copy link
Author

Sure, am just currently busy and wanted to get that possible regression reported as quick as possible :) will setup a minimal repro in the coming days if still necessary by then 🤞

@panva
Copy link
Owner

panva commented Apr 27, 2023

It is necessary because I want to re-introduce the PR eventually.

@panva panva closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2023
@panva
Copy link
Owner

panva commented May 5, 2023

Feel free to come back with a repro on your own time. I'll close this for now.

@dargmuesli
Copy link
Author

I always expected me to do this on my own time. Leaving that part out of the invitation to come back with a reproduction would keep the message and sound less harsh 😄

@panva
Copy link
Owner

panva commented May 5, 2023

Didn't mean to sound harsh, and even re-reading it still doesn't sound like so to me. What I meant is, feel free to come back with a repro anytime not being pressured by an open issue that's waiting on you, that's all :)

@dargmuesli
Copy link
Author

The issue is in the following section:

jose/src/types.d.ts

Lines 94 to 97 in f079ca3

type JsonObject = { [Key in string]?: JsonValue }
type JsonArray = JsonValue[]
type JsonPrimitive = string | number | boolean | null
type JsonValue = JsonPrimitive | JsonObject | JsonArray

There is a loop between JsonValue and JsonObject.

@dargmuesli
Copy link
Author

Based on https://stackoverflow.com/a/50516408/4682621 it might be a solution to define JsonObject like this:

type JsonObject<T> = {
  [K in keyof T]?: T[K] extends object ? JsonObject<T[K]> :
    T[K] extends JsonPrimitive | JsonArray ? T[K] : never
}

But I'm not that kind of typescript pro, so please validate that suggestion thoroughly!

@panva
Copy link
Owner

panva commented May 7, 2023

Curcular referencing is not an issue and I've had this code in other projects for a long time with no issues. That's why I need a minimal reproduction, to be able to rule out that this isn't a problem caused by something else in your stack. From the looks of it in your screenshot it is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for feedback The OP is asked for feedback or a proposal
Projects
None yet
Development

No branches or pull requests

2 participants