Answer the question
In order to leave comments, you need to log in
How do I fix the "Instance of type is too deep and possibly infinite.ts(2589)" error in my case?
Answer the question
In order to leave comments, you need to log in
TypeScript limits the nesting of recursion so that the typechecker works quickly and does not freeze.
You can reduce the nesting if you process several parts at once:
type Split<S extends string, D extends string = ''> = S extends ''
? []
: S extends `${infer H0}${D}${infer H1}${D}${infer H2}${D}${infer H3}${D}${infer H4}${D}${infer H5}${D}${infer Tail}`
? [H0, H1, H2, H3, H4, H5, ...Split<Tail, D>]
: S extends `${infer H0}${D}${infer H1}${D}${infer H2}${D}${infer H3}${D}${infer Tail}`
? [H0, H1, H2, H3, ...Split<Tail, D>]
: S extends `${infer H0}${D}${infer Tail}`
? [H0, ...Split<Tail, D>]
: never;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question