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

TypeCheck<any> results in TS2589: Type instantiation is excessively deep and possibly infinite. #798

Closed
SimenB opened this issue Mar 20, 2024 · 2 comments

Comments

@SimenB
Copy link

SimenB commented Mar 20, 2024

import type { TypeCheck } from '@sinclair/typebox/compiler';

const checker: TypeCheck<any> = {} as any;

checker.Decode({});

While reducing the reproduction I figured out I could use TypeCheck<TUnknown> which works, but I thought to still report it 🙂

@sinclairzx81
Copy link
Owner

sinclairzx81 commented Mar 20, 2024

Hi @SimenB! :)

Ah, this is a good catch actually. I just published a quick fix for this on 0.32.17. In the update, passing <any> for the generic parameter is permitted (as it does technically pass the TSchema constraint), however the StaticDecode will infer as unknown if it detects any is being passed. I've drafted a bit of info on the fix over at #799

Let me know if this helps resolve things :)
Cheers!
S

@SimenB
Copy link
Author

SimenB commented Mar 20, 2024

Cool, thanks! Using TypeCheck<TUnknown> is fine in our case (it's really <T extends TSchema = any>, then TypeCheck<T> that was in our codebase, and defaulting to TUnknown rather than any is a better solution 😀)

@SimenB SimenB closed this as completed Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants