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 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 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 How to Create Arrays of Generic Interfaces in TypeScript ? In TypeScript, managing data structures effectively is crucial for building robust applications. Arrays of generic interfaces provide a powerful mechanism to handle varied data types while maintaining type safety and flexibility. There are various methods for constructing arrays of generic interface 3 min read How to Return a Union Type in TypeScript ? In TypeScript, a union type is a powerful way to express a variable that can be one of several types. Union types are used when a function or variable is expected to support multiple types of input. Union types are defined using the pipe (|) symbol between two or more types. This indicates that a va 4 min read Generics Interface in typescript "A major part of software engineering is building components that not only have well-defined and consistent APIs but are also reusable. " This sentence is in the official documentation we would start with. There are languages that are strong in static typing & others that are weak in dynamic typ 5 min read Generics Interface in typescript "A major part of software engineering is building components that not only have well-defined and consistent APIs but are also reusable. " This sentence is in the official documentation we would start with. There are languages that are strong in static typing & others that are weak in dynamic typ 5 min read Interfaces in TypeScript TypeScript is a statically typed superset of JavaScript that adds optional types, classes, interfaces, and other features to help developers build robust and maintainable applications. One of the most powerful features of TypeScript is interfaces, which allow you to define the structure of objects, 4 min read What are intersection types in Typescript ? In Typescript, Although intersection and union types are similar, they are employed in completely different ways. An intersection type is a type that merges several kinds into one. This allows you to combine many types to create a single type with all of the properties that you require. An object of 3 min read Like