Do You Really Know These 6 TypeScript Utilities?
1. Pick
With Pick
, you can pick a set of keys from the given type.
userName variable is now used to ensure only those two fields are set.
2. Omit
In constrast to Pick, you can use Omit to remove a set of Keys (basically omit a set of properties) from your Type.
3. Partial
This utility will make a new Type set with all the properties of the Type set, set to optional.
This is ultimately the same as redefining the User type to,
4. Readonly
Readonly is used when you don’ t want the properties of an object reassigned. As in the name, it will set the properties of Type set to read-only.
5. Return Type
The utility type ReturnType helps by extracting the return type of a function.
6. Non-Nullable
It excludes null and undefined from the given Type.
If you want to write cleaner code or you just want to have tips like this every week, so you can follow me on medium will be more likely to show you the next article.
Drop me a ‘Hi’ on:
WhatsApp: +94719994818
Facebook: iAbu94
Email: iabu94.dev@gmail.com