How to check interface type in TypeScript ? Last Updated : 29 Sep, 2020 Comments Improve Suggest changes Like Article Like Report Typescript is a pure object-oriented programming language that consists of classes, interfaces, inheritance, etc. It is strict and it statically typed like Java. Interfaces are used to define contacts in typescript. In general, it defines the specifications of an entity. Below is an example of an interface or contract of a car. interface Audi { length: number; width: number; wheelbase: number; price:number; numberOfAirBags:number; seatingCapacity: number; getTyrePressure: () => number; } Approach: Declare an interface with a name and its type as a string.Now create a customized function to check the interface type.This function returns a boolean value if the name attribute is present in the argument passed.Now use an if statement to check the value returned by the function and can perform further operation regarding requirements. Example 1: JavaScript interface Student{ name:string; } var geek:any = { name: "Jairam" }; function instanceOfStudent(data: any): data is Student { return 'name' in data; } if (instanceOfStudent(geek)) { document.write("Student Name is "+ geek.name); } Output:Â Example 2: JavaScript interface Bike{ companyName:string; bikeNumber:any; modelNo:any; } var bike:any = { companyName: "Engfield" }; function createName(name:any){ alert(name); } if(instanceOfBike(bike)) { createName(bike.companyName) } else{ createName("No Name is registered with that company name") } function instanceOfBike(data: any): data is Bike { return 'companyName' in data; } Output:Â Comment More infoAdvertise with us Next Article How to check interface type in TypeScript ? B bunnyram19 Follow Improve Article Tags : JavaScript Web Technologies TypeScript Similar Reads How to Check Types in Typescript? Checking types in TypeScript involves methods like typeof for primitive types, instanceof for class instances, and custom type guards for complex type validation. These techniques help ensure variables are correctly typed, improving code safety, and readability, and preventing runtime errors.Here ar 3 min read How to Check the Type of an Object in Typescript ? When working with TypeScript, understanding how to check the type of an object is crucial for ensuring type safety and maintaining code integrity. TypeScript, being a statically typed superset of JavaScript, provides several approaches to accomplish this task as listed below.Table of ContentUsing th 3 min read How to Cast Object to Interface in TypeScript ? In TypeScript, sometimes you need to cast an object into an interface to perform some tasks. There are many ways available in TypeScript that can be used to cast an object into an interface as listed below: Table of Content Using the angle bracket syntaxUsing the as keywordUsing the spread operatorU 3 min read How to Extract Interface Members in TypeScript ? In TypeScript, you can extract interface members (properties and methods) from a class using several approaches. we are going to learn how to extract interface members in TypeScript. Below are the approaches used to extract interface members in TypeScript: Table of Content Manual Extractionimplement 3 min read TypeScript Interfaces Type TypeScript Interfaces Type offers an alternative method for defining an object's type, allowing for a distinct naming approach. Syntax:interface InterfaceName { property1: type1; property2?: type2; readonly property3: type3; // ... method1(): returnType1; method2(): returnType2; // ...}Parameters:in 2 min read Like