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

Make has method a type guard #205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yotamN
Copy link

@yotamN yotamN commented Aug 29, 2024

While widening the has method helps, it still cause problems with cases where we want to access the data later:

if (map.has(key)) {
  map.get(key); // will fail since key was not narrowed
}

@mattpocock
Copy link
Owner

mattpocock commented Sep 1, 2024

Please add tests, and once tests are added you'll notice the flaws in your implementation.

For instance, map.has(key) doesn't guarantee that key is type typeof key.

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

Successfully merging this pull request may close these issues.

3 participants