1.

What are the ‘implements’ clauses in TypeScript?

Answer»

An implements clause is used to check that a class satisfies the contract specified by an interface. If a class implements an interface and doesn’t IMPLEMENT that interface, the TypeScript compiler issues an error.

interface Runnable {run(): void;}class Job implements Runnable {run() { console.log("RUNNING the scheduled job!");}}// Class 'Task' incorrectly implements interface 'Runnable'.// Property 'run' is missing in type 'Task' but required in type 'Runnable'.(2420)class Task implements Runnable {PERFORM() { console.log("pong!");}}

A class can implement more than ONE interface. In this case, the class has to specify all the contracts of those interfaces.



Discussion

No Comment Found