#Excessively deep type instantiation

1 messages · Page 1 of 1 (latest)

frozen forgeBOT
#
balam314#0

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 ...

lucid knoll
#

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

lucid knoll
#

!helper

tepid scroll
#

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

timber grove
#

you can also avoid the problem by writing out the index signature rather than using Record:

frozen forgeBOT
#
mkantor#0

Preview:ts ... te : T extends RecordVariableType ? {[key: string]: VariableTypeMapping<any>} : T extends ArrayVariabl ...