Skip to content

Commit

Permalink
Merge branch 'total-typescript:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ecancino committed Feb 2, 2024
2 parents 10d65e1 + b2df073 commit 100cc86
Show file tree
Hide file tree
Showing 16 changed files with 400 additions and 307 deletions.
94 changes: 94 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,99 @@
# @total-typescript/ts-reset

## 0.5.1

### Patch Changes

- Added homepage for npm purposes.

## 0.5.0

### Minor Changes

- 49b8603: Added a rule, `/session`, to make sessionStorage and localStorage safer.

```ts
// 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.

## 0.4.1

### Patch Changes

- No changes, just pushing to fix the previous slightly borked release.

## 0.4.0

### Minor Changes

- ce9db42: Added support for widening in `Array.lastIndexOf`, `Array.indexOf`, `ReadonlyArray.lastIndexOf` and `ReadonlyArray.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.

```ts
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` 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");
```

### Patch Changes

- b15aaa4: Fixed an oversight with the initial `set-has` implementation by adding support to `ReadonlySet`.

## 0.3.7

### Patch Changes
Expand Down
Binary file added og-image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@total-typescript/ts-reset",
"version": "0.3.7",
"version": "0.5.1",
"description": "A CSS reset for TypeScript, improving types for common JavaScript API's",
"private": false,
"repository": "https://github.com/total-typescript/ts-reset",
"homepage": "https://totaltypescript.com/ts-reset",
"scripts": {
"build": "tsx scripts/build.ts",
"ci": "turbo build check-exports lint lint-pkg-json",
Expand Down Expand Up @@ -58,10 +59,30 @@
"import": "./dist/set-has.mjs",
"default": "./dist/set-has.js"
},
"./map-has": {
"types": "./dist/map-has.d.ts",
"import": "./dist/map-has.mjs",
"default": "./dist/map-has.js"
},
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.mjs",
"default": "./dist/utils.js"
},
"./array-index-of": {
"types": "./dist/array-index-of.d.ts",
"import": "./dist/array-index-of.mjs",
"default": "./dist/array-index-of.js"
},
"./dom": {
"types": "./dist/dom.d.ts",
"import": "./dist/dom.mjs",
"default": "./dist/dom.js"
},
"./storage": {
"types": "./dist/storage.d.ts",
"import": "./dist/storage.mjs",
"default": "./dist/storage.js"
}
},
"keywords": [],
Expand Down

0 comments on commit 100cc86

Please sign in to comment.