# prefer-map-has

Prefer Map.has over Map.get when only key presence is observed

Comparing `Map.get` with `undefined` retrieves a value only to determine whether its key exists.
Instead, you SHOULD call `Map.has` when the mapped value cannot itself be `undefined`.

- Category: performance
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function contains(values: Map<string, int32>, key: string): boolean {
    return values.get(key) !== undefined;
}
```

## Accepted

```ds title="main.ds"
function contains(values: Map<string, int32>, key: string): boolean {
    return values.has(key);
}
```

## Prior art

- [eslint-plugin-unicorn · prefer-has-check](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-has-check.md)

[language/linter/src/rules/performance/prefer_map_has.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/prefer_map_has.rs#L8)
