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

Set.has should accept any type #44542

Closed
5 tasks done
ktmud opened this issue Jun 10, 2021 · 2 comments
Closed
5 tasks done

Set.has should accept any type #44542

ktmud opened this issue Jun 10, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@ktmud
Copy link

ktmud commented Jun 10, 2021

Suggestion

Currently if you do

const mySet = new Set(['foo'] as const])
mySet.has('bar')

Line 2 throws an Argument of type '"bar"' is not assignable to parameter of type '"foo"' error.

However, set.has(...) is meant to detect whether an element is in the set, therefore by definition it should be able to accept arguments that are not in the set---in which case, it just returns false.

It seems the fix is simply replace

has(value: T): boolean;
with

    has(value: any): boolean;

🔍 Search Terms

set, has, dom, lib, any, type, const

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow set.has(...) to accept any arguments that are not in the set.

📃 Motivating Example

N/A

💻 Use Cases

N/A

@IllusionMH
Copy link
Contributor

Looks like a duplicate of #42641

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 10, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants