3 ms·
In the fixed version of #3, the function return type is `Product[]` instead of `any`. The example is further refined in #4. What type guards are good for is ma
by jgwil2 6y ago
In the fixed version of #3, the function return type is `Product[]` instead of `any`. The example is further refined in #4.
What type guards are good for is marrying the compile time checks with runtime safety. They allow TSC to infer that in a given code path, the type can be narrowed down to something more specific. This is nice because it lets a single function e.g. handle a few different types without littering your code with `as` or `!`.