How to apply a function type to a function declaration

You can’t specify types for function declarations. You can only use Parameters and ReturnType. The only minor improvement would be to use destructuring for the parameters:

type Add = (x:number, y:number) => number
function add(...[x, y]: Parameters<Add>): ReturnType<Add> {
    return x + y;
}

Playground Link

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)