2020年12月31日星期四

How to abort early with Type instantiation is excessively deep and possibly infinite

type PathFinder<    TFieldValues,    Key extends keyof TFieldValues = keyof TFieldValues,  > = Key extends string    ? TFieldValues[Key] extends FileList      ? Key      : TFieldValues[Key] extends (ArrayChild)[] | Set<ArrayChild>      ? `${Key}.${Indexes}`      : TFieldValues[Key] extends object[]      ? `${Key}.${Indexes}.${PathFinder<ArrayElementType<TFieldValues[Key]>>}`      : TFieldValues[Key] extends Record<string, any>      ? `${Key}.${PathFinder<TFieldValues[Key]>}`      : Key    : never;    type test = PathFinder<{ test: string }>   type test = PathFinder<Record<string, any>> // cause error  

I have the above type to type object path, however, some of my function's generic is Recrod<string, any> is there any way to skip or abort early so this error can be avoided?

Playground

https://stackoverflow.com/questions/65527030/how-to-abort-early-with-type-instantiation-is-excessively-deep-and-possibly-infi January 01, 2021 at 11:00AM

没有评论:

发表评论