Skip to content

Commit

Permalink
Improve is plain object typings (#1231)
Browse files Browse the repository at this point in the history
* ci: remove bench exclude

* chore: move bench in their respective packages

* chore(deps): to latest

* chore: rename bench-dist into bench

* chore: rename bench-dist into bench

* feat: add compartive benchmarks

* chore: add benchmark config

* chore: remove bench workspace

* feat: improve isPlainObject

* feat: improve isPlainObject

* chore(deps): nx to latest

* fix(bench): typecheck shouldn't choke for benchmarks

* fix(bench): typecheck shouldn't choke for benchmarks
  • Loading branch information
belgattitude authored May 24, 2024
1 parent 702f8a7 commit fd2ecd3
Show file tree
Hide file tree
Showing 124 changed files with 1,118 additions and 1,082 deletions.
3 changes: 1 addition & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@bench/*"]
"updateInternalDependencies": "patch"
}
40 changes: 40 additions & 0 deletions .changeset/quick-coats-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
"@httpx/assert": minor
---

Improve PlainObject convenience typings when passing a generic.

```typescript
import { isPlainObject, assertPlainObject } from '@httpx/assert';

type TValue = {
key: string,
deep: {
connected: boolean
}
}
const value = {
key: 'hello',
deep: {
connected: true
}
} as unknown;

// Without generic

assertPlainObject(value);
// value is Record<string, unknown>
// -> no typing

value.key; // unknown, no runtime error
value.anything; // unknown, no runtime error
// value.deep.connected // not possible without explicit typing

// With generic

assertPlainObject<TValue>(value);

value.key; // unknown, no runtime error
value.anything; // unknown, no runtime error
value.deep?.connected; // connected is 'unknown', typescript suggest the type
```
4 changes: 2 additions & 2 deletions .github/workflows/ci-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ jobs:
- name: 🕵️ Typecheck
if: matrix.node-version == '20.x'
run: yarn nx run-many --target=typecheck --exclude='examples/**' --exclude='bench/**' --exclude='docs'
run: yarn nx run-many --target=typecheck --exclude='examples/**' --exclude='docs'

- name: 🔬 ESLint checks
if: matrix.node-version == '20.x'
run: yarn nx run-many --target=lint --exclude='examples/**' --exclude='bench/**' --exclude='docs'
run: yarn nx run-many --target=lint --exclude='examples/**' --exclude='docs'

- name: 🧪 Unit tests (no-coverage - node !== 20.x)
if: matrix.node-version != '20.x'
Expand Down
36 changes: 18 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ If applicable:

## Local scripts

| Name | Description |
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `yarn g:changeset` | Add a changeset to declare a new version |
| `yarn g:typecheck` | Run typechecks in all workspaces |
| `yarn g:lint` | Display linter issues in all workspaces |
| `yarn g:lint --fix` | Attempt to run linter auto-fix in all workspaces |
| `yarn g:test-unit` | Run unit tests in all workspaces |
| `yarn g:build` | Run build in all workspaces |
| `yarn g:clean` | Clean builds in all workspaces |
| `yarn g:check-dist` | Ensure build dist files passes es2017 (run `g:build` first). |
| `yarn g:check-size` | Ensure build files are within size limit (run `g:build` first). |
| `yarn g:docgen` | Build documentation (generally api doc) |
| `yarn g:bench-dist` | Run comparative benchmarks of latest |
| `yarn clean:global-cache` | Clean tooling caches (eslint, jest...) |
| `yarn deps:check --dep dev` | Will print what packages can be upgraded globally (see also [.ncurc.yml](https://github.com/belgattitude/httpx/blob/main/.ncurc.yml)) |
| `yarn deps:update --dep dev` | Apply possible updates (run `yarn install && yarn dedupe` after) |
| `yarn check:install` | Verify if there's no peer-deps missing in packages |
| `yarn dedupe` | Built-in yarn deduplication of the lock file |
| Name | Description |
|------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `yarn g:changeset` | Add a changeset to declare a new version |
| `yarn g:typecheck` | Run typechecks in all workspaces |
| `yarn g:lint` | Display linter issues in all workspaces |
| `yarn g:lint --fix` | Attempt to run linter auto-fix in all workspaces |
| `yarn g:test-unit` | Run unit tests in all workspaces |
| `yarn g:build` | Run build in all workspaces |
| `yarn g:clean` | Clean builds in all workspaces |
| `yarn g:check-dist` | Ensure build dist files passes es2017 (run `g:build` first). |
| `yarn g:check-size` | Ensure build files are within size limit (run `g:build` first). |
| `yarn g:docgen` | Build documentation (generally api doc) |
| `yarn g:bench` | Run benchmarks for all workspaces. |
| `yarn clean:global-cache` | Clean tooling caches (eslint, jest...) |
| `yarn deps:check --dep dev` | Will print what packages can be upgraded globally (see also [.ncurc.yml](https://github.com/belgattitude/httpx/blob/main/.ncurc.yml)) |
| `yarn deps:update --dep dev` | Apply possible updates (run `yarn install && yarn dedupe` after) |
| `yarn check:install` | Verify if there's no peer-deps missing in packages |
| `yarn dedupe` | Built-in yarn deduplication of the lock file |

## Git message format

Expand Down
6 changes: 0 additions & 6 deletions bench/assert/.eslintignore

This file was deleted.

47 changes: 0 additions & 47 deletions bench/assert/.eslintrc.cjs

This file was deleted.

37 changes: 0 additions & 37 deletions bench/assert/.gitignore

This file was deleted.

106 changes: 0 additions & 106 deletions bench/assert/bench/benchmark-results.json

This file was deleted.

55 changes: 0 additions & 55 deletions bench/assert/package.json

This file was deleted.

35 changes: 0 additions & 35 deletions bench/assert/src/benchmarks.ts

This file was deleted.

Loading

0 comments on commit fd2ecd3

Please sign in to comment.