In this issue, I walk you through Type Narrowing, what it is and techniques we can use to do Type narrowing.
Hello, Maina
How are you?
Thanks for the article. I've appreciated read it. I have a doubt though.
The "square" function have a bug for the value 0 (zero). So the "if" will catch it, even if its type is "number" and throw an error.
Best regards :)
Hey @kabrunko,
Thanks for pointing that out.
I see what you mean and yeah, it's a bug, but for simplicity's sake when teaching typescript types, we didn't add in checks to ensure that the numbers are positive, which in the real world should be added.
Hello, Maina
How are you?
Thanks for the article. I've appreciated read it. I have a doubt though.
The "square" function have a bug for the value 0 (zero). So the "if" will catch it, even if its type is "number" and throw an error.
Best regards :)
Hey @kabrunko,
Thanks for pointing that out.
I see what you mean and yeah, it's a bug, but for simplicity's sake when teaching typescript types, we didn't add in checks to ensure that the numbers are positive, which in the real world should be added.