How to narrow arguments with a union type?
I have an argument that is number | string
, and try to derive a variable that is a number
.
The following code shows what I expected to work. (That kind of thing would work in Python.)
Type narrowing using early returns to infer an object contains a property
I am writing a type guard for an object. I use early returns to keep the indentation readable, but the example is contrived.