Search⌘ K

Nullable

Explore how to build nullable types in TypeScript using mapped types. This lesson guides you through creating specific nullable interfaces and generalizing them with generics, helping you write efficient, maintainable code that adapts easily to changes.

Nullable mapped type

Another possibility with the mapped type is that it can handle null. Similar to the optional Partial<T>, you can create your own Nullable<T>. To create your own type, the first step is to build it with no generic (without <T>, a plain interface or type) and then adjust it by adapting with a ...