#Understand multiple call signature syntax

2 messages · Page 1 of 1 (latest)

tropic tapir
#

Hi!

I don't understand why a2's value does not respect type a. TS says:

Type '(n: number) => void' is not assignable to type 'a'.
  Target signature provides too few arguments. Expected 1 or more, but got 0.

Which I do not understand. I would expect it to accept a function that has 1 parameter.

type a = {
    (): void;
    (n: number): void;
}

type b = (() => void) | ((n: number) => void)

const a1: a = () => {}
const a2: a = (n: number) => {}

const b1: b = () => {}
const b2: b = (n: number) => {}

Can someone explain to me what's wrong?

https://www.typescriptlang.org/fr/play?#code/C4TwDgpgBAhlC8UDeAoK6oAoCUAuKAbgPYCWAJgNxoaYB2+tArgLYBGEATnoaZSgL4oUoSFFYIsOBAD4e5bFAA+k+lCZtOC+LOLyhAYyK0AzsFgBGfHERTtyQYZNmYAJisS6DFuy4z7Bo1MxSzEPLVkkB0CzVjdQm1V1H3D-IA

pallid aspen
#

having multiple signatures means the object can be called with any of the signatures, like how an overloaded function would work