What does the following type-level Fibonacci implementation use? type BuildArr = Arr[‘length’] extends N ? Arr : BuildArr; type Add = […BuildArr, …BuildArr][‘length’];

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following type-level Fibonacci implementation use? type BuildArr = Arr[‘length’] extends N ? Arr : BuildArr; type Add = […BuildArr, …BuildArr][‘length’];

Key points

  • Tuple lengths represent numbers
  • Spread operator used for addition
  • Enables type-level arithmetic
  • Recursive approach for building arrays
  • Utilizes TypeScript's type system effectively

Ready to go further?

Related questions