Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

unknown definitely helps, but it doesn't solve the problem. You still need to get the data from unknown -> your type. Most people will resort to casting, which is unsafe. Runtime type libraries let you know _for sure_ that the type is correct.

example: https://tinyurl.com/yc74stm6

I adopted this pattern at work for all of our API calls, local storage, route parameters, etc.. The result was the app was fully typed, and we handled every case of invalid data in a reasonable way. When data is invalid, we can provide a sane default value.



Definitely agreed that it's not a perfect solution, just that it's better than blindly using `any`. Using type assertions to get around it defeats the point, though, and it is frustrating when people do that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: