-
Notifications
You must be signed in to change notification settings - Fork 161
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
TS 4.5: Type instantiation is excessively deep and possibly infinite. #120
Comments
I also have issues with this even in 0.20.6. My repro is at https://replit.com/@SteveHiggs/GrumpyQuizzicalFields |
@gmaclennan @stevejhiggs Thanks for reporting. Just taking a deeper look into this now. It looks like there's been fairly significant changes in 4.5. I'm guessing this is probably related to the following microsoft/TypeScript#46429. I'll start looking at a patch within the next few days. |
Thanks @sinclairzx81. Sticking to Typescript 4.4 keeps everything working for now :) |
The simplest build I came up with: {
"@sinclair/typebox": "0.20.6",
"typescript": "4.5.2"
} import {
Static,
TSchema,
} from '@sinclair/typebox';
export function validate<ResponseSchema extends TSchema>(
data: Static<ResponseSchema>
): Static<ResponseSchema> {
return data;
}
|
@gmaclennan Have published an update on These updates are fairly sweeping type inference changes to accommodate these new 4.5 constraints, but these updates should also work in previous revisions of the compiler, have tested back to the minimum version of TS 4.3.5 and things should be ok. Let me know if you run into any problems |
Can confirm that 0.21.0 fixes all the issues I was having. Amazing work, thanks! |
Amazing, much appreciated! |
Cheers everyone :) Will close off this issue. Thanks for letting me know! |
I know this issue is old and I don't have problems using with typescript 5 but this error happens when I try to rollup types with api-extractor which is using bundled ts with version @sinclairzx81 Do you have any tips or solution regarding this? Warning: node_modules/.pnpm/@[email protected]/node_modules/@sinclair/typebox/typebox.d.ts:110:47 - (TS2589) Type instantiation is excessively deep and possibly infinite. |
@ayZagen Hi, Looking at the line number, it appears to be related to If possible, you can use ReproWould it be possible to share a repro of the Type you're having problems with? You should be able post it up on the TypeScript Playground and repro by setting the compiler version to Hope this helps |
@ayZagen Quick code paste for TS ExampleThe following example intersects 3 objects with overlapping properties. The overlapping properties are combined into a distributed import { Type, Static } from '@sinclair/typebox'
type T = Static<typeof T> // type T = { x: never, y: never, z: never }
const T = Type.Composite([ // const T: TObject<{
Type.Object({ // x: TIntersect<[TNumber, TString, TBoolean]>, - (TNever)
x: Type.Number(), // y: TIntersect<[TNumber, TString, TBoolean]>, - (TNever)
y: Type.Number(), // z: TIntersect<[TNumber, TString, TBoolean]>, - (TNever)
z: Type.Number(), // }>
}),
Type.Object({
x: Type.String(),
y: Type.String(),
z: Type.String(),
}),
Type.Object({
x: Type.Boolean(),
y: Type.Boolean(),
z: Type.Boolean(),
}),
]) |
@sinclairzx81 Thanks for the detailed responses! Strangely though I tried downgrading to Now I am using dts-bundle-generator and have no issues. Thanks. |
Adding this here as another datapoint in case it's helpful for others--I encountered a similar issue to @ayZagen in a project using Typescript I agree with the suspicion that it's specific to Anyway, this isn't too rough for my use case as I'd rather not have typebox schemas in my public API anyway: the only reason they were there in the first place is because of this api-extractor issue: microsoft/rushstack#3616. If someone else encounters this and needs to dig deeper, this should be the compiler API invocation which causes these errors in API-extractor: https://github.com/microsoft/rushstack/blob/c31f6c5be835823dfd9004d721f9fc89dca4945d/apps/api-extractor/src/collector/Collector.ts#L195. Edit: Curiosity got the better of me on the version mismatch. With respect to API extractor seemingly using 4.8.4 when --typescript-compiler-folder is specified, the doc I linked above isn't particularly clear with what that option does. Its CLI doc here makes it more clear this only affects the system typings, which matches the code here. So it seems like expected behavior that api-extractor can only use the typescript version being bundled. |
I know this has already had a quick fix via #119 but with
@sinclair/[email protected]
I still get this error for this very basic code:Error returned:
Minimal repro here: https://github.com/gmaclennan/typebox-error-repro
Error running on CI: https://github.com/gmaclennan/typebox-error-repro/runs/4251888078?check_suite_focus=true
For what it's worth, I checked with other version of Typebox, and this code compiles with v0.11.0 but fails on any later version including v0.20.6
The text was updated successfully, but these errors were encountered: