More advanced type syntaxes for another day
(A veryfast reference overview below. Don't worry if you don't understand something, just know that those exist, so you can research later.)
Mapped types is a syntax used to declare generic objects.
Mapped types can be used to remap one object type to another, by iterating over its keys.
keyof
lists all possible keys of an object type as a type union;
Properties may me accessed with
[""]
Conditional types were created to solve a dozen of the type system's limitations. Its name may be misleading. One of the dozen things conditional types can do is to "pick" a type from inside another type expression. For instance:
The standard type lib includes some auxiliary type aliases like
Record
andOmit
. All of those type aliases are made by composing the features previously shown. You can check all available helpers and its implementation by CTRL+Clicking any of them.
When you want to dig deeper, I'd strongly recommend checking the Typescript playground samples session.
Last updated