Should I use typeof in TypeScript?

typeof is used when you need to distinguish between types number , string , boolean , and symbol . Other string constants will not error, but won’t be used to narrow types either. Unlike instanceof , typeof will work with a variable of any type. In the example below, foo could be typed as number | string without issue.

Read more

What does typeof do in TypeScript?

typeof is used to differentiate between the different types in TypeScript . By the use of typeof we can differentiate between number, string, symbol, Boolean, etc. typeof can be used with any type in TypeScript, by the use of it we can re-use the code by passing any parameter type.

Read more