Skip to content

Commit

Permalink
Changed Map.has docs and added changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Mar 8, 2023
1 parent 6673bc2 commit 4765413
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .changeset/olive-pets-exist.md
@@ -0,0 +1,38 @@
---
"@total-typescript/ts-reset": minor
---

author: @mefechoel

Added the `Map.has` rule.

Similar to `.includes` or `Set.has()`, `Map.has()` doesn't let you pass members that don't exist in the map's keys:

```ts
// BEFORE
const userMap = new Map([
["matt", 0],
["sofia", 1],
[2, "waqas"],
] as const);

// Argument of type '"bryan"' is not assignable to
// parameter of type '"matt" | "sofia" | "waqas"'.
userMap.has("bryan");
```

With the rule enabled, `Map` follows the same semantics as `Set`.

```ts
// AFTER
import "@total-typescript/ts-reset/map-has";

const userMap = new Map([
["matt", 0],
["sofia", 1],
[2, "waqas"],
] as const);

// .has now takes a string as the argument!
userMap.has("bryan");
```
14 changes: 11 additions & 3 deletions readme.md
Expand Up @@ -227,20 +227,28 @@ Similar to `.includes` or `Set.has()`, `Map.has()` doesn't let you pass members

```ts
// BEFORE
const userMap = new Map([["matt", 0], ["sofia", 1], [2, "waqas"]] as const);
const userMap = new Map([
["matt", 0],
["sofia", 1],
[2, "waqas"],
] as const);

// Argument of type '"bryan"' is not assignable to
// parameter of type '"matt" | "sofia" | "waqas"'.
userMap.has("bryan");
```

With the rule enabled, `Map` is much smarter:
With the rule enabled, `Map` follows the same semantics as `Set`.

```ts
// AFTER
import "@total-typescript/ts-reset/map-has";

const userMap = new Map([["matt", 0], ["sofia", 1], [2, "waqas"]] as const);
const userMap = new Map([
["matt", 0],
["sofia", 1],
[2, "waqas"],
] as const);

// .has now takes a string as the argument!
userMap.has("bryan");
Expand Down

0 comments on commit 4765413

Please sign in to comment.