Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Map.has docs and added changeset
- Loading branch information
1 parent
6673bc2
commit 4765413
Showing
2 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters