Skip to content

Commit

Permalink
Merge branch 'main' of github.com:total-typescript/ts-reset into map-…
Browse files Browse the repository at this point in the history
…unknown-41
  • Loading branch information
mattpocock committed May 27, 2024
2 parents a2a4414 + ff2551f commit 626be7e
Show file tree
Hide file tree
Showing 20 changed files with 2,345 additions and 1,741 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- "**"
pull_request:
branches:
- "**"

jobs:
build:
Expand Down
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 38 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"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": {
"dev": "tsc --watch",
"build": "tsx scripts/build.ts",
"ci": "turbo build check-exports lint lint-pkg-json",
"check-exports": "check-export-map",
Expand Down Expand Up @@ -63,21 +65,50 @@
"import": "./dist/map-constructor.mjs",
"default": "./dist/map-constructor.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": [],
"author": "Matt Pocock",
"license": "MIT",
"devDependencies": {
"@changesets/cli": "^2.26.0",
"@types/node": "^18.14.0",
"check-export-map": "^1.3.0",
"tsx": "^3.12.3",
"turbo": "^1.8.1",
"typescript": "^4.9.5"
"@changesets/cli": "^2.27.3",
"@types/node": "^18.19.33",
"check-export-map": "^1.3.1",
"tsx": "^3.14.0",
"turbo": "^1.13.3",
"typescript": "^5.4.5"
},
"prettier": {
"arrowParens": "always",
"trailingComma": "all",
"semi": true,
"printWidth": 80,
"singleQuote": false,
"tabWidth": 2,
"useTabs": false
}
}
Loading

0 comments on commit 626be7e

Please sign in to comment.