I think Interface rarely have both anonymous and named function. Is this right?
TypeScript compiler allows interface to have both anonymous and named function.
// no error
interface Foo {
(x: number, y: number): number; // anonymous
namedMethod: (z: string, w: string) => string; // named
}
But it seems unavailable.
// badProp is not assignable
const foo1 : Foo = {
badProp(x: number, y: number) { return 1 },
namedMethod(a: string, b: string) { return 'str'; }
}
// syntax error
const foo2 : Foo = {
(x: number, y: number) { return 1 },
namedMethod(a: string, b: string) { return 'str'; }
}
using any type, it works.
const temp: any = function (x: number, y: number) { return 1 };
temp.namedMethod = function (a: string, b: string) { return 'str'; }
const foo3: Foo = temp;
Though using both is Technically possible, Interface rarely have both anonymous and named function. Is this right?