gvergnaud / hotscript

A library of composable functions for the type-level! Transform your TypeScript types in any way you want using functions you already know.
3.38k stars 57 forks source link

create `GetArg` type to simplify the `arg0`-`arg3` code in `Fn` #88

Closed DetachHead closed 1 year ago

DetachHead commented 1 year ago

i was trying to do something like this, but i don't think it's possible

export interface Fn {
  [rawArgs]: unknown;
  args: this[rawArgs] extends infer args extends unknown[] ? args : never;
  [Key in `arg${number}`]: GetArg<this, Key extends `arg${infer Index}` ? Index : never>
  return: unknown;
}
gvergnaud commented 1 year ago

Hey,

Thank you for contributing, but I don't really think this simplifies the code, it just makes it more abstract. We don't need this extra abstraction here.

We need to be careful about the number of nested function calls we make, to reach the recursive limit as late as possible.