- 757be40: Fixed a bug where creating an empty map would no longer infer types correctly.
-
6574858: Added a rule,
/map-constructor
, to defaultMap
toMap<unknown, unknown>
when no arguments are passed to the constructor.Before, you'd get
any
for both key and value types. Now, the result ofMap.get
isunknown
instead ofany
:const userMap = new Map(); const value = userMap.get("matt"); // value: unknown
This now is part of the recommended rules.
-
5bf3a15: Added a rule,
/promise-catch
, to change thecatch
method to takeunknown
instead ofany
as an argument.const promise = Promise.reject("error"); // BEFORE promise.catch((error) => { console.error(error); // error is any! }); // AFTER promise.catch((error) => { console.error(error); // error is unknown! });
-
53cee4f: author: @none23
Fixed a bug where running .filter on a union of arrays would not work.
- Added homepage for npm purposes.
-
49b8603: Added a rule,
/session
, to make sessionStorage and localStorage safer.// Is now typed as `unknown`, not `any`! localStorage.a; // Is now typed as `unknown`, not `any`! sessionStorage.abc;
-
49b8603: Added a
/dom
entrypoint to allow users to import DOM-only rules.
- No changes, just pushing to fix the previous slightly borked release.
-
ce9db42: Added support for widening in
Array.lastIndexOf
,Array.indexOf
,ReadonlyArray.lastIndexOf
andReadonlyArray.indexOf
. -
107dfc2: Changed the array.includes on readonly arrays to NOT be a type predicate. Before this change, this perfectly valid code would not behave correctly.
type Code = 0 | 1 | 2; type SpecificCode = 0 | 1; const currentCode: Code = 0; // Create an empty list of subset type const specificCodeList: ReadonlyArray<SpecificCode> = []; // This will be false, since 0 is not in [] if (specificCodeList.includes(currentCode)) { currentCode; // -> SpecificCode } else { // This branch will be entered, and ts will think z is 2, when it is actually 0 currentCode; // -> 2 }
Removing the type predicate brings ts-reset closer towards correctness.
-
4765413: author: @mefechoel
Added the
Map.has
rule.Similar to
.includes
orSet.has()
,Map.has()
doesn't let you pass members that don't exist in the map's keys:// 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 asSet
.// 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");
- b15aaa4: Fixed an oversight with the initial
set-has
implementation by adding support toReadonlySet
.
- Added license and switched to MIT
- d3ddefa: Changed the exports map so "types" appears top
- Another fix for deploy process.
- Fixed an issue where dist folder was not deployed.
- Fixed a bug where 0n was not being filtered out by filter-boolean
- Removed the ability to use Set.has as a type predicate. This ensures that Set.has never sets the checked element to never.
- Fixed a bug where Array.includes was returning a predicate, which gave false positives.
- ed9edc1: Added improved typings for Set.has
- d27e819: Fixed issue where webpack wasn't recognizing the exports map
- Readme tweak
- e5a33c9: Added support for array.includes
- 8fe8e29: Improved filter-boolean to handle falsy values, not just NonNullable values
- Fixed exports (finally)
- bb3f2d1: Attempted fix for exports maps
- 4cfb07e: Fixed build process and moved to .d.ts files
- 0360275: Fixed type imports
- e62b05a: Added .npmignore
- 51628fc: Initial commit