jonáš
jonáš
TTCTheo's Typesafe Cult
Created by jonáš on 7/15/2024 in #questions
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.
6 replies