Do You Really Know These 6 TypeScript Utilities?

Abdullah Mansoor
2 min readSep 19, 2022

--

ts utilities

1. Pick

With Pick, you can pick a set of keys from the given type.

pick

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.

omit

3. Partial

This utility will make a new Type set with all the properties of the Type set, set to optional.

partial

This is ultimately the same as redefining the User type to,

partial redefined

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.

readonly

5. Return Type

The utility type ReturnType helps by extracting the return type of a function.

return type

6. Non-Nullable

It excludes null and undefined from the given Type.

non-nullable

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

Follow me on:
LinkedIn: iabu94
Twitter:
iabu94
GitHub:
iabu94

--

--

Abdullah Mansoor
Abdullah Mansoor

Written by Abdullah Mansoor

Full Stack Developer (.Net + Angular)

Responses (2)