Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature idea: Change Map from any --> unknown #41

Open
Zamiell opened this issue Feb 21, 2023 · 7 comments
Open

Feature idea: Change Map from any --> unknown #41

Zamiell opened this issue Feb 21, 2023 · 7 comments

Comments

@Zamiell
Copy link

Zamiell commented Feb 21, 2023

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: microsoft/TypeScript#52552

@m10rten
Copy link

m10rten commented Feb 23, 2023

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.

@Zamiell
Copy link
Author

Zamiell commented Feb 23, 2023

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.

@mattpocock
Copy link
Collaborator

Agree, this issue deserves to stay open! My response is on the PR

@nmay231
Copy link

nmay231 commented Mar 18, 2023

FYI, the title should be "any --> unknown" 🙂

@Zamiell Zamiell changed the title Feature idea: Change Map from unknown --> any Feature idea: Change Map from any --> unknown Mar 19, 2023
@Crisfole
Copy link

Ultimately this is just about the default value, so Map<K = unknown, V = unknown> right?

@Zamiell
Copy link
Author

Zamiell commented Jan 11, 2024

yes

@arnorhs
Copy link

arnorhs commented May 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants