sinclairzx81 / typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
Other
4.98k stars 157 forks source link

Typescript 5.1.6: Type instantiation is excessively deep and possibly infinite. #484

Closed p-kuen closed 1 year ago

p-kuen commented 1 year ago

Similar as stated in #119 the same error occurs with Typescript version 5.1.6:

node_modules/.pnpm/@sinclair+typebox@0.28.20/node_modules/@sinclair/typebox/typebox.d.ts:179:167 - error TS2589: Type instantiation is excessively deep and possibly infinite.

179 ] extends [TArray, TNumber] ? AssertType<T['items']> : K extends TTemplateLiteral ? TIndexReduce<T, TTemplateLiteralKeyRest<K>> : K extends TUnion<TLiteral<Key>[]> ? TIndexReduce<T, TUnionLiteralKeyRest<K>> : K extends TLiteral<Key> ? TIndexReduce<T, [K['const']]> : TNever;
                                                                                                                                                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 1 error in node_modules/.pnpm/@sinclair+typebox@0.28.20/node_modules/@sinclair/typebox/typebox.d.ts:179

I tested it on Typescript version 5.1.5 and it works, so it's just the difference in these two patch versions. (see https://github.com/microsoft/TypeScript/compare/v5.1.5...release-5.1).

Maybe it's a bug in the TypeScript version but as the problem already occurred with this package some time ago, I thought I will report it here.

sinclairzx81 commented 1 year ago

@p-kuen Hi, thanks for the heads up. Will investigate.

sinclairzx81 commented 1 year ago

@p-kuen Heya,

Have a patch for this that should be ready on TB 0.29.0 (so minor semver). Will look to publish this within the next 24 hours or so (as there is some other changes due to roll through on this revision). Will notify when TB has been published with the fix.

Thanks again for reporting!

sinclairzx81 commented 1 year ago

@p-kuen Hi,

This patch should be applied on 0.29.0. If you can just give things a quick test your side, can close up this issue. Again, thanks for reporting the issue so promptly (was actually good timing given the revision going out).

I still don't know if this was a bug in the compiler or intended functionality, however it was a breaking change in inference behavior on a semver PATCH revision (5.1.3 -> 5.1.6). Generally these issues lead to better / faster inference in TB, but sorta wish there was a system of being notified of potential breaking compiler changes prior to TS publishing on npm, I may do some looking into.

Thanks again S

p-kuen commented 1 year ago

Hi, thanks for the quick fixes. Unfortunately I am using typebox through the @fastify/type-provider-typebox package which is currently bound to 0.28.x versions. So I have to wait until an update from this package until I can test it in my environment. I will give an update after I checked it again.

Thanks again!

knicola commented 1 year ago

confirming 0.29.x fixes the issue

sinclairzx81 commented 1 year ago

@knicola Hi, thanks for confirming!

@p-kuen May close off this issue for now as the issue appears resolved and the type provider may take some time to update. Note the Fastify organization manages this provider, so to help fast track things, just open and issue or submit a PR to bump the peerDependency there. Can CC me on that repository if there's any issues with the update.

Thanks all!

p-kuen commented 1 year ago

Alright, thanks for the hint! I created a PR in fastify/fastify-type-provider-typebox#90.

SimenB commented 1 year ago

sorta wish there was a system of being notified of potential breaking compiler changes prior to TS publishing on npm, I may do some looking into.

They publish nightlies, so one thing you could do is set up a cron job in this repo to at least run your tests. Might catch these before release?

sinclairzx81 commented 1 year ago

@SimenB Hi! That's a great idea! :)

Have just setup a GH Action to run a build against TS latest and next once daily. Was also looking into typescript-error-deltas the other day where I think TS track regressions their side across a number of community packages. I may see if they'll accept a PR to include TB in their test suite. Could probably add quite a few type mapping libraries to their tests as these kinds of libraries do tend to push out the extents of the compiler.

Thanks again for the suggestion! All the best S

jessekrubin commented 1 year ago

@sinclairzx81 Love it when my build fails and there's already a fixed version!