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

Example in Tuples.GroupBy is incorrect #110

Open cstria0106 opened 10 months ago

cstria0106 commented 10 months ago

Document says

interface IsNumber extends Fn {
  return: this["arg0"] extends number ? true : false;
}

type T0 = Call<Tuples.GroupBy<IsNumber>, [1, "str", 2]>;
//   ^? { true: [1, 2], false: ["str"] }
type T2 = Call<Tuples.GroupBy<Strings.StartsWith<"a">>, ["alice", "bob", "carl"]>;
//   ^? { true: ["alice"], false: ["bob", "carl"] }

But it's actually

interface IsNumber extends Fn {
  return: this['arg0'] extends number ? true : false;
}

type T0 = Call<Tuples.GroupBy<IsNumber>, [1, 'str', 2]>;
// never
type T2 = Call<Tuples.GroupBy<Strings.StartsWith<'a'>>, ['alice', 'bob', 'carl']>;
// never

Because boolean can not be the property name