diff --git a/.changeset/olive-pets-exist.md b/.changeset/olive-pets-exist.md new file mode 100644 index 0000000..f4a038f --- /dev/null +++ b/.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"); +``` diff --git a/readme.md b/readme.md index 874aca8..a64e6d9 100644 --- a/readme.md +++ b/readme.md @@ -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");