Default implementation of functions that you want in the TypeScript interface
TypeScript Version:5.5.3 Node Version :18.14.2
interface Greeting {
sayGoodbye(name: string): void = {
console.log(`Goodbye, ${name}!`);
};
}
class EnglishGreeting implements Greeting {
sayGoodbye(name: string): void {
throw new Error("Method not implemented.");
}
sayHello(name: string): void {
console.log(`Hello, ${name}!`);
}
}
If the compilation fails in the above way, whether the interface can support the default implementation of the function