Good catch regarding the load, I will update the example.
You are also right, that we can use it inline, but the idea was also to discuss the type guards. If this check is extracted it can be reused across the app if necessary and it also improves readability of the code.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In the type guard example truck with
load
of0
will be considered asF1
because0
is falsy. It is better to check usingin
operator:Such check can be used even without writing type guard function:
typescriptlang.org/docs/handbook/a...
Good catch regarding the
load
, I will update the example.You are also right, that we can use it inline, but the idea was also to discuss the type guards. If this check is extracted it can be reused across the app if necessary and it also improves readability of the code.