TypeScript InstanceType<Type> Utility Type Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we are going to learn about InstanceType<Type> Utility Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, the InstanceType<Type> utility type is used to extract the instance type of a constructor function or class type. It allows you to infer the type of instances that can be created from a constructor or class. Syntaxtype T1 = InstanceType<Type>;ParametersType: This is the type parameter that represents the constructor function or class type from which you want to extract the instance type.T1: This is the name of the utility type that extracts the instance type.Example 1In this example, We have a Person class with a constructor that takes a name and an age.We use InstanceType<typeof Person> to extract the instance type of the Person class, which is equivalent to { name: string; age: number; }.We create an instance of Person using new Person("Alice", 30) and assign it to the person variable.TypeScript infers that person is of type PersonInstance, which allows us to access the name and age properties of the person object with type safety. JavaScript class Person { constructor(public name: string, public age: number) { } } type PersonInstance = InstanceType<typeof Person>; const person: PersonInstance = new Person("Alice", 30); console.log(person.name); // "Alice" console.log(person.age); // 30 Output Example 2In this example, We have a Product class with a constructor that takes a name and a price.We also have a ShoppingCart class that can hold instances of Product.InstanceType<typeof Product> is used to specify the type of products that can be added to the shopping cart.We create instances of Product (e.g., laptop and smartphone) and an instance of ShoppingCart (e.g., cart).We add products to the cart using the addItem method.We calculate the total price of the items in the cart using the getTotalPrice method JavaScript class Product { constructor(public name: string, public price: number) { } } class ShoppingCart { private items: InstanceType<typeof Product>[] = []; addItem(product: InstanceType<typeof Product>): void { this.items.push(product); } getTotalPrice(): number { return this.items.reduce((total, product ) => total + product.price, 0); } } // Create instances of Product const laptop = new Product("Laptop", 1000); const smartphone = new Product("Smartphone", 500); // Create an instance of ShoppingCart const cart = new ShoppingCart(); // Add products to the cart cart.addItem(laptop); cart.addItem(smartphone); // Get the total price of the items in the cart const totalPrice = cart.getTotalPrice(); // Output: Total Price: $1500 console.log(`Total Price: $${totalPrice}`); Output Reference: https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype Comment More infoAdvertise with us Next Article TypeScript InstanceType<Type> Utility Type 21mcsrltd Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 +1 More Similar Reads TypeScript ThisType<Type> Utility Type The TypeScript ThisType<Type> utility type allows you to define the type of this within a specific object or function context, providing precise type checking for methods and properties accessed through this. The ThisType<Type> utility type is primarily used to provide type annotations f 3 min read TypeScript ReturnType <Type> Utility Type The ReturnType<Type> utility type in TypeScript extracts and infers the return type of a given function type. It enhances type safety and reusability by allowing developers to dynamically determine the type of values returned by functions without manually specifying them.Syntaxtype ResultTypeV 3 min read TypeScript Creating Types from Utility Type TypeScript Creating Types from Utility Type increases the code readability and ease of use when using any complex operations and values, there are different ways to do the type creation with the existing ones. TypeScript Creating Types from Utility Type:Generics: It basically allows us to declare th 3 min read TypeScript Utility Types TypeScript utility types are predefined constructs that facilitate common type transformations, enhancing code flexibility and maintainability. They allow developers to modify existing types easily, such as by making properties optional or read-only.Utility types help in creating more expressive and 5 min read What is the Record Type in TypeScript ? In TypeScript, the Record type is a utility type that represents an object type with keys and values of a specific type. It is often used when you want to define a type for the keys and values of an object. In this article, we will learn what is the Record type in TypeScript. Syntax:Record<Keys, 2 min read Like