TypeScript 5.4
code:ts
function createStreetLight<C extends string>(colors: C[], defaultColor?: C) {
// ...
}
Cの推論はcolorsに対してのみ行いたい。
code:ts
function createStreetLight<C extends string, D extends C>(colors: C[], defaultColor?: D) {
}
// ~~~~~~
// error!
// Argument of type '"blue"' is not assignable to parameter of type '"red" | "yellow" | "green" | undefined'.
Dは他で使ってないのでダルい
code:ts
function createStreetLight<C extends string>(colors: C[], defaultColor?: NoInfer<C>) {
// ...
}
// ~~~~~~
// error!
// Argument of type '"blue"' is not assignable to parameter of type '"red" | "yellow" | "green" | undefined'.
そのためのNoInfer
Object.groupBy
Map.groupBy
requireをimport??