let f1: {(): number}
let f2: () => number
let f3: {() => number} // error TS1005: ':' expected.
It looks like f1 and f2 declarations are equivalent, is it true?
And why f3 is an error?
The notation with the braces allows you to define overload method signatures and/or hybrid types, for example
interface Foo {
(x: number): void,
(x: string): void,
bar: string,
}
has two call signatures and one property bar.
If you only have one call signature and no properties you can use the shorthand syntax you used for f2. So with the braces you have to separate the arguments from the return type with : and in the shorthand syntax with =>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With