Troubleshooting Handbook: Operators
typeof
andinstanceof
: type query used for refinementkeyof
: get keys of an objectO[K]
: property lookup[K in O]
: mapped types+
or-
orreadonly
or?
: addition and subtraction and readonly and optional modifiersx ? Y : Z
: Conditional types for generic types, type aliases, function parameter types!
: Nonnull assertion for nullable types=
: Generic type parameter default for generic typesas
: type assertionis
: type guard for function return types
Conditional Types are a difficult topic to get around so here are some extra resources:
- fully walked through explanation https://artsy.github.io/blog/2018/11/21/conditional-types-in-typescript/
- Bailing out and other advanced topics https://github.com/sw-yx/ts-spec/blob/master/conditional-types.md
- Basarat's video https://www.youtube.com/watch?v=SbVgPQDealg&list=PLYvdvJlnTOjF6aJsWWAt7kZRJvzw-en8B&index=2&t=0s