February 2019
Beginner
694 pages
18h 4m
English
Mapped types that transform properties to optional, or transform properties to readonly, are seen as so fundamental that they have been included in the standard TypeScript type definitions. In other words, we can use Partial<T> to create a type where all properties of T are optional, or ReadOnly<T> to create a type where all properties of T are readonly. To create these mapped types for our IAbcRequired interface, we can simply write the following:
type partialAbc = Partial<IAbcRequired>; type readonlyAbc = Readonly<IAbcRequired>;
Here, the type partialAbc is a copy of the IAbcRequired type, but with all properties marked as optional. Similarly, the type readonlyAbc is a copy of the IAbcRequired type, ...
Read now
Unlock full access