I'm using TypeScript 4.2.4. Say I have the following TypeScript code.
// perfectly legal syntax
interface MyInterface {
attr1: number;
(): number;
}
// Compilation error: Type '{ attr1: number; }' provides no match for the signature '(): number'
let x: MyInterface = {
attr1: 1
};
// Compilation error: Property 'attr1' is missing in type '() => number' but required in type
let y: MyInterface = () => {
return 1;
}
Did I just create an unusable interface? How such interface can be used?
Please don't mind the example not making any sense. I'm asking this question to learn the language.