What are ‘implements’ clauses in TypeScript ? Last Updated : 09 Mar, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In Typescript an implements clause can be used to verify that a class conforms to a specific interface. If a class fails to implement an interface correctly, an error will be generated. Classes can implement a single interface or multiple interfaces at once. Example 1: An interface A is created with has a function display of type void. Class B and Class C implement interface A. Class B doesn't raise an error as method display is properly implemented but class C has a method Display(), which is different from the method defined in the interface, so typescript compiler raises an error that class 'C' incorrectly implements interface 'A'. JavaScript // Creating an interface interface A { display(): void; } class B implements A { display() { console.log("B"); } } class C implements A { // Throws error: Class 'C' incorrectly // implements interface 'A'. // Property 'display' is missing in type // 'C' but required in type 'A'. Display() { console.log("C"); } } Output: error TS2420: Class 'C' incorrectly implements interface 'A'. Property 'display' is missing in type 'C' but required in type 'A'. class C implements A { ~ display(): void; ~~~~~~~~~~~~~~~~ 'display' is declared here.Example 2: If an additional property exists in an interface does not make that property exist in the class that implements it unless the properties are defined. In such cases typescript compiler raises errors. JavaScript interface A { propA: number; propB: number; } class B implements A { propA = 0; } const obj = new B(); obj.propB = 3; Output: Reference: https://www.typescriptlang.org/docs/handbook/2/classes.html#implements-clauses Comment More infoAdvertise with us Next Article What is Type Erasure in TypeScript? I isitapol2002 Follow Improve Article Tags : TypeScript Geeks-Premier-League-2022 JavaScript-Questions Similar Reads What are Generics in TypeScript ? In this article, we will try to understand all the facts as well as the details associated with Generics in TypeScript along with some coding examples. Generics in TypeScript: Whenever any program or code is written or executed, one major thing one always takes care of which is nothing but making re 3 min read What are the Modules in Typescript ? Modules in TypeScript allow you to organize code into reusable, manageable, and logical units by encapsulating functionalities into separate files.They help avoid global namespace pollution by providing scoped declarations.Modules can be imported and exported, enabling code reuse and better maintain 4 min read What are TypeScript Interfaces? TypeScript interfaces define the structure of objects by specifying property types and method signatures, ensuring consistent shapes and enhancing code clarity.Allow for optional and read-only properties for flexibility and immutability.Enable interface inheritance to create reusable and extendable 4 min read What's the Difference Between 'extends' and 'implements' in TypeScript ? TypeScript offers powerful way for organizing code and managing relationships between different components through the use of extends and implements keywords. This article explores the distinctions and functionalities of these two keywords.ExtendsThe extends keyword is used for two main purposes in 2 min read What is Type Erasure in TypeScript? TypeScript is a very mighty superset of JavaScript, which adds static typing to the language and allows developers to catch errors early on as well as write more maintainable code. This being said a TypeScript type system erases type information at compile time (or during the compilation), a phenome 4 min read What are template literal types in Typescript ? Template literal types in TypeScript allow the construction of new string literal types by combining existing string literal types using template literal syntax.They enable the creation of complex string patterns by embedding unions and other literal types within template literals.This feature enhan 3 min read Like