-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve is plain object typings (#1231)
* 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
1 parent
702f8a7
commit fd2ecd3
Showing
124 changed files
with
1,118 additions
and
1,082 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.