3 ms·
> As an aside, using `any` gives you the worst of both worlds: you have to fight with a type system, and the type system isn't even doing anything Not sure I a
by IshKebab 3y ago
> As an aside, using `any` gives you the worst of both worlds: you have to fight with a type system, and the type system isn't even doing anything
Not sure I agree there. You can use `any` judiciously so that don't have to fight the type system where it's too difficult, and yet still get the benefits elsewhere in your program.
I think it's actually one of the biggest benefits of dynamic typing - in rare cases you can use `any`. Most static type systems don't really let you do that. (I think Dart is one of the rare exceptions because it started dynamically typed and switched to statically typed.)
- shepherdjerred 3y agoIf you're using `any` just because the type is complex, then using it sparingly isn't a huge deal, so long as you are confident that the type is correct. The problem is using `any` when you _don't_ actually know the type of something, e.g. ``` const data = JSON.parse(localStorage.get("my_data")) as any as UserSettings; ``` In the above case you're just hoping that what's in local storage matches your type, and it makes your type system less effective.