sinclairzx81 / typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
Other
4.77k stars 152 forks source link

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

Closed SimenB closed 5 months ago

SimenB commented 5 months ago
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 commented 5 months ago

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 https://github.com/sinclairzx81/typebox/pull/799

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

SimenB commented 5 months ago

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 😀)