Use An Array Check For Type Narrowing
If you are typing a concatenation function for melding two values together into a single array, you may end up with a function signature like this:
That first argument can be an individual value or an array of values. You'll need to handle both scenarios in the function implementation. Using the Array.isArray
function as a type guard, you can check differentiate between those two cases.
This is a form of type narrowing.
PreviousType Narrowing With Similarly Shaped ObjectsNextZero-Config Environments For Trying Out Types
Last updated