初めに
TypeScriptの型システムはチューリング完全なので何でも計算できます。
例えば繰り返し。
type Repeat<T, N extends number, R extends any[] = []> = R["length"] extends N
? R
: Repeat<T, N, [T, ...R]>;
// type A = ["x", "x", "x", "x", "x", "x", "x", "x", "x", "x"]
type A = Repeat<"x", 10>;
わーい。ちょっと数増やすか…
// error TS2589: Type instantiation is excessively deep and possibly infinite.
type A = Repeat<"x", 100>;
あれ?(つらい)
再帰制限解除したいですね。しましょう。
注意
当然ですがプロダクトで使うことは想定していません、やめましょう。
バージョンなど
[email protected].