Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4765413

Browse files
committed
Changed Map.has docs and added changeset
1 parent 6673bc2 commit 4765413

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

.changeset/olive-pets-exist.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
"@total-typescript/ts-reset": minor
3+
---
4+
5+
author: @mefechoel
6+
7+
Added the `Map.has` rule.
8+
9+
Similar to `.includes` or `Set.has()`, `Map.has()` doesn't let you pass members that don't exist in the map's keys:
10+
11+
```ts
12+
// BEFORE
13+
const userMap = new Map([
14+
["matt", 0],
15+
["sofia", 1],
16+
[2, "waqas"],
17+
] as const);
18+
19+
// Argument of type '"bryan"' is not assignable to
20+
// parameter of type '"matt" | "sofia" | "waqas"'.
21+
userMap.has("bryan");
22+
```
23+
24+
With the rule enabled, `Map` follows the same semantics as `Set`.
25+
26+
```ts
27+
// AFTER
28+
import "@total-typescript/ts-reset/map-has";
29+
30+
const userMap = new Map([
31+
["matt", 0],
32+
["sofia", 1],
33+
[2, "waqas"],
34+
] as const);
35+
36+
// .has now takes a string as the argument!
37+
userMap.has("bryan");
38+
```

readme.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,28 @@ Similar to `.includes` or `Set.has()`, `Map.has()` doesn't let you pass members
227227

228228
```ts
229229
// BEFORE
230-
const userMap = new Map([["matt", 0], ["sofia", 1], [2, "waqas"]] as const);
230+
const userMap = new Map([
231+
["matt", 0],
232+
["sofia", 1],
233+
[2, "waqas"],
234+
] as const);
231235

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

237-
With the rule enabled, `Map` is much smarter:
241+
With the rule enabled, `Map` follows the same semantics as `Set`.
238242

239243
```ts
240244
// AFTER
241245
import "@total-typescript/ts-reset/map-has";
242246

243-
const userMap = new Map([["matt", 0], ["sofia", 1], [2, "waqas"]] as const);
247+
const userMap = new Map([
248+
["matt", 0],
249+
["sofia", 1],
250+
[2, "waqas"],
251+
] as const);
244252

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

0 commit comments

Comments
 (0)