ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.47k stars 31 forks source link

Excessive stack depth comparing types 'ParseMixedSchema<?, T>' and 'ParseMixedSchema<?, T>'. #56

Closed ericvicenti closed 2 years ago

ericvicenti commented 2 years ago

Hello and thank you for this awesome library! (my little project needs TS safety and serializable schemas, so I would be screwed without json-schema-to-ts!)

This error frequently appears in my codebase when TS performs deep inference with a FromSchema type:

Screen Shot 2022-04-01 at 2 59 05 PM

Heres a Youtube video where I demo this code and we see the issue: https://youtu.be/O2xGGEOYYyI?t=438

Somehow TS gets tripped up, and I only see this error when working with JSON-schema-to-ts codebases.

I have not found any way to "TS-Ignore" this, without causing breaks to useful type safety. As you can see in the screenshot, the "number" schema is being TS-ified correctly.

This example is open source here: https://github.com/zerve-app/zerve/blob/main/apps/demo-server/DemoServer.ts#L8-L10

Any advice or help would be greatly appreciated! ❤️

ThomasAribart commented 2 years ago

Hi @ericvicenti and thanks for the issue 👍

Is the issue still happening with v2.0.0 ? It reminds me of another issue, can you try rolling back to v1.6.4 ?

ThomasAribart commented 2 years ago

Hi @ericvicenti, I cloned zerve and tried to reproduce the issue but couldn't. Does it still exist ?

ericvicenti commented 2 years ago

Thanks @ThomasAribart

Actually yes, I was on the older version of json-schema-to-ts! I put the demo code back into the same state as when I posted this issue. Also I updated TS and this lib. Now I see this error instead of the "ParseMixedSchema" error:

Screen Shot 2022-04-11 at 5 47 29 PM

So I guess this issue can be closed because ParseMixedSchema is no longer involved 😅 But I don't know how to address this "excessively deep and possibly infinite" issue. 🙃

ThomasAribart commented 2 years ago

@ericvicenti Okay I did some research.

It turns out that you do recursive typing that TS doesn't really like ^^ I have a PR ready for you on zerve to fix this if you want 👍

It also comes from what is probably a bug in TS, as described in https://github.com/ThomasAribart/json-schema-to-ts/issues/53, that I've managed to isolate in my PR so VSCode can still run smoothly.

Can you gimme the right to push on zerve ? I've been denied the git push so I can't open it

ericvicenti commented 2 years ago

Just gave you write access to zerve. Thank you for investigating!

I'll be mostly offline for the next few days, but let me know what I can do to help when I get back.

Update(Thu)- I was on GH mobile and it apparently failed to add you 😒 You actually have write access now.