Skip to content

Commit

Permalink
Merge branch 'main' of github.com:total-typescript/ts-reset into davi…
Browse files Browse the repository at this point in the history
…dneil-promise-catch
  • Loading branch information
mattpocock committed May 27, 2024
2 parents 5b41583 + 8568d22 commit 8b47eaf
Show file tree
Hide file tree
Showing 25 changed files with 2,466 additions and 1,750 deletions.
15 changes: 15 additions & 0 deletions .changeset/rude-knives-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@total-typescript/ts-reset": minor
---

Added a rule, `/map-constructor`, to default `Map` to `Map<unknown, unknown>` when no arguments are passed to the constructor.

Before, you'd get `any` for both key and value types. Now, the result of `Map.get` is `unknown` instead of `any`:

```ts
const userMap = new Map();

const value = userMap.get("matt"); // value: unknown
```

This now is part of the recommended rules.
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ on:
push:
branches:
- "**"
pull_request:
branches:
- "**"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 7
version: 9
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
cache: "pnpm"

- run: pnpm install --frozen-lockfile
Expand Down
100 changes: 100 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
# @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

- Added license and switched to MIT

## 0.3.6

### Patch Changes
Expand Down
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 Matthew Pocock

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
52 changes: 44 additions & 8 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.6",
"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 @@ -58,21 +60,55 @@
"import": "./dist/set-has.mjs",
"default": "./dist/set-has.js"
},
"./map-constructor": {
"types": "./dist/map-constructor.d.ts",
"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": "ISC",
"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 8b47eaf

Please sign in to comment.