4 ms·
The Typescript team has been pushing the use of `unknown` instead of `any` for typing data at the boundaries of your app; how much of that has shown up in the e
by DylanSp 3y ago
The Typescript team has been pushing the use of `unknown` instead of `any` for typing data at the boundaries of your app; how much of that has shown up in the ecosystem?
EDIT: I definitely agree with your general point, for the record.
- shepherdjerred 3y agounknown 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 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.
- DylanSp 3y agoDefinitely 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.