TypeScript NonNullable<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 NonNullable<Type> Utility Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, the NonNullable<Type> utility is used to create a new type by removing null and undefined from the given type. It ensures that the resulting type only contains non-null and non-undefined values. Syntax:type NonNullableType = NonNullable<Type>;Where- NonNullableType is the name of the new type that will contain non-null and non-undefined values.Type is the original type from which you want to remove null and undefined.Example 1: In this example, OriginalType is a type that can either be a string, null, or undefined.NonNullableType is created by applying the NonNullable<OriginalType> utility, which removes null and undefined from OriginalType. JavaScript // Original type with // nullable and undefined values type OriginalType = string | null | undefined; // Applying NonNullable utility // to remove null and undefined type NonNullableType = NonNullable<OriginalType>; const value1: NonNullableType = "GeeksforGeeks"; // Valid console.log(value1) //const value2: NonNullableType = null; // Error: Type 'null' is not // assignable to type 'string'. //const nonNullableValue3: NonNullableType = undefined; // Error: Type 'undefined' is //not assignable to type 'string'. Output: Example 2: In this example, OriginalType is a type representing an object with a name property of type string and course property that can be a string, null, or undefined. We create a new type called NonNullableCourseType by using the NonNullable<OriginalType["course"]> utility to remove null and undefined from the course property. JavaScript // Original type with nullable and undefined values type OriginalType = { name: string; course: string | null | undefined; }; // Applying NonNullable utility to // remove null and undefined from 'course' type NonNullableCourseType = { name: string; course: NonNullable<OriginalType["course"]>; }; const person1: NonNullableCourseType = { name: "GeeksforGeeks", course: 'Java', }; // Valid console.log(person1) // const person2: NonNullableCourseType = { // name: "GeeksforGeeks", // course: null, // }; //Error: Type 'null' is // not assignable to type 'string'. // const person3: NonNullableCourseType = { // name: "GeeksforGeeks", // course: undefined, // }; //Error: Type 'undefined' is not //assignable to type 'string'. Output: Comment More infoAdvertise with us Next Article TypeScript NonNullable<Type> Utility Type A abhiisaxena09 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 +1 More Similar Reads TypeScript Readonly <Type> Utility Type In this article, we are going to learn about Readonly<Type> Utility Type in Typescript. Typescript is a popular programming language used for building scalable and robust applications. One of the features of Typescript is Readonly<Type> Utility Type which is used to create a new type whe 2 min read Typescript Required<Type> Utility Type TypeScript's Required<Type> utility type creates a new type by making all properties of an existing type mandatory. It removes optionality from each property, ensuring that all fields must be provided, which enhances type safety and reduces potential errors in type definitions.Syntaxtype Requi 3 min read 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 Omit<Type, Keys> Utility Type TypeScript's Omit<Type, Keys> utility type creates a new type by excluding specific properties (Keys) from an existing type (Type). It is useful for refining types by removing unnecessary properties, enhancing type safety, and simplifying complex type definitions in TypeScript applications.Syn 4 min read TypeScript OmitThisParameter<Type> Utility Type In this article, we are going to learn about OmitThisParameter<Type> Utility Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, the OmitThisParameter<Type> utility type is used to create a new function type 3 min read TypeScript InstanceType<Type> Utility Type 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 constr 3 min read TypeScript Extract<Type, Union> Utility Type In this article, we are going to learn about Extract<Type, Union> utility type in TypeScript, TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tools at any scale. Extract<Type, Union> utility type is used to extract a subset of types from a 4 min read TypeScript - Recursive Types and Utility Types TypeScript adds strong typing to JavaScript. Recursive Types define types that refer to themselves, useful for trees or nested objects. Utility Types simplify type changes, like making properties optional or read-only. These tools help write clear and flexible code.Recursive Types in TypeScriptA rec 3 min read How to declare nullable type in TypeScript ? In vanilla JavaScript, there are two primary data types: null and undefined. While TypeScript previously did not allow explicit naming of these types, you can now use them regardless of the type-checking mode. To assign undefined to any property, you need to turn off the --strictNullChecks flag. How 2 min read Like