I would like to add types to one of my older code-bases and can’t seem to make types with spread operator work. I tried to make a simplified example of the issue.
const f = <T, U>(...[a, b]:T[]) => (...[x, y]:U[]) => {}
// -
type Signature<T, U> = (...t:T[]) => (...u:U[]) => void
function c<T, U>(f:Signature<T, U>){}
// -
type Params = [a:number, b?:number]
type Inputs = [x:[number, number[]], y:[number, number[]]]
c<Params, Inputs>(f(1))
To explain what is going on, this example may look counterintuitive but it is part of a library where there are variations of function f
that should be pluggable into function c
but some generics have to be passed for f
to have types and still be compatible with the function c
that accepts different types of f
.
https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240624#code/FAYw9gdgzgLgBAMzgXjgHgCoBo4FUB8AFAHSkDaAhjgEYC6AXBmbQJQr5wnkAeOAng1zM2yDgG8AvsGAB6GXAC00mHwAOAUzgBlAJYBzCBRgBXAE7rMOAik6liMRsPa3Sx+kNbOAbmB0ATaQRjCBAYHUg4EEs8IgR6XQMjMwtsGJZJaTlFZTVNAAUKUwoAWygbSnoIY2LqdVMaAH5K6trTWhyNOABJCFVjGDLUMm56Miqaupxx1uZaflHpybhF01n20DQCotKcHr6B2MIARhYWIA