ts-reset
ts-reset copied to clipboard
Feature idea: Change Map from any --> unknown
Both of the default generic parameters of Map are any.
You should change them to unknown for the same reasons that you e.g. change JSON.parse.
For a more in-depth discussion on this, see: https://github.com/microsoft/TypeScript/issues/52552
Maps already have a generic option: Map<K, T>() where as JSON.parse does not, I think the goal is to improve existing features and not add generics everywhere, that said, if you do not set the K & T it will be any.
Up for debate, it is safer, but you can also just add a starting generic.
I'm aware that maps have generic parameters. The point of this issue is that sometimes programmers forget to specify the generic parameters, so the default generic parameters are used, which means that any slips into the codebase, which should be solved at the type-level.
Agree, this issue deserves to stay open! My response is on the PR
FYI, the title should be "any --> unknown" :slightly_smiling_face:
Ultimately this is just about the default value, so Map<K = unknown, V = unknown> right?
yes
So, what is the status of the PR?
Seems like the test is accurate - I had the same defined myself in a big repo at work, and it has not caused any issues - i suggest this ends up being merged.