Preview:ts ... export type VariableTypeMapping<T> = T extends "INTEGER" ? number : T extends "DATE" ? Date : T extends RecordVariableType ? Record<string, VariableTypeMapping<any>> //ERROR: excessively deep : T extends ArrayVariableType ? Array<Va ...
#Excessively deep type instantiation
1 messages · Page 1 of 1 (latest)
VariableTypeMapping returns the type of the JS value used to store the value of a variable of type T in a programming language runtime
in this programming language, T can be an arbitrarily deep record, with arrays and other stuff mixed in
I'm trying to get the correct typing but end up breaking TS instead
!helper
use the lazy evaluation trick or whatever there was the docs
gimme sec
i cant find it but the basic idea is adding something like
T extends infer U ? U : never
so it stops recursion there
TypeScript 4.5 Release Notes
you can also avoid the problem by writing out the index signature rather than using Record:
Preview:ts ... te : T extends RecordVariableType ? {[key: string]: VariableTypeMapping<any>} : T extends ArrayVariabl ...