Do you have to check type by using Array.isArray in TypeScript when you know the type?

Hi guys, I'm moderately experienced dev (4 years of JavaScript/TypeScript, 3 years of React) and I'm currently looking for a job. In the recent home task during interview process, I've got a feedback that I have a mistake in this component https://github.com/JonasMerxbauer/siteone/blob/master/src/components/CheckboxForm.tsx where I should be checking if the checkboxes is actual array by using Array.isArray(checkboxes). But I feel like that it's not necessary because there is no way that I would have a anything else than array there unless someone else would do weird shenanigans like const a = "str" as boolean[] or that I would be getting the array from api/db but then I would be checking the type at the place where I am fetching the data so I have always correct type down the line and not in component. I would understand this in Javascript but what would be even be the point of using TypeScript if I would have to always manually check if the variable is correct type? What's your opinion about this, have I been doing this wrong all the time or am I right that it's not necessary to check in this situation? I have gone through to the next round but this just seems so stupid to me. Thank you very much in advance.
GitHub
siteone/src/components/CheckboxForm.tsx at master · JonasMerxbauer/...
Contribute to JonasMerxbauer/siteone development by creating an account on GitHub.
Solution:
their side is off and wrong
Jump to solution
3 Replies
Solution
Neto
Neto5mo ago
their side is off and wrong
Neto
Neto5mo ago
if someone does a '' as unknown as boolean[] it's on them and the review should catch it
jonáš
jonášOP5mo ago
Good to hear, thank you
Want results from more Discord servers?
Add your server