https://github.com/peterboyer/pb.types
Utility types like Equal, Intersect, Identity and more.
https://github.com/peterboyer/pb.types
typescript
Last synced: 5 months ago
JSON representation
Utility types like Equal, Intersect, Identity and more.
- Host: GitHub
- URL: https://github.com/peterboyer/pb.types
- Owner: peterboyer
- License: mit
- Created: 2024-11-04T12:34:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-17T22:45:35.000Z (10 months ago)
- Last Synced: 2025-10-30T05:56:11.717Z (9 months ago)
- Topics: typescript
- Language: TypeScript
- Homepage: https://npmjs.com/pb.types
- Size: 86.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pb.types
> [!NOTE]
> Renamed from `pb.expectequal`.
>
> Combines [`pb.expectequal`](https://github.com/peterboyer/pb.expectequal),
[`pb.intersect`](https://github.com/peterboyer/pb.intersect), and
[`pb.identity`](https://github.com/peterboyer/pb.identity) into a single
[`pb.types`](https://github.com/peterboyer/pb.types) package.
## Installation
```shell
npm install pb.types
```
## Requirements
- `typescript@>=5.0.0`
- `tsconfig.json > "compilerOptions" > { "strict": true }`
## API
- More information available as jsdoc strings in linked source files below.
### `Expect,Equal,NotEqual`
- [`Expect`](./src/expect.ts)
- [`Equal`](./src/equal.ts)
- [`NotEqual`](./src/not-equal.ts)
```ts
import type { Expect, Equal, NotEqual } from "pb.types";
const result = JSON.stringify({});
!0 as Expect>;
!0 as Expect>;
```
### `Intersect`
- [`Intersect`](./src/intersect.ts)
```ts
import type { Intersect } from "pb.types";
type Example = { A: true } | { B: true } | { C: true };
type Result = Intersect;
// ^ { A: true } & { B: true } & { C: true }
// ^ { A: true; B: true; C: true }
```
### `Identity`
- [`Identity`](./src/identity.ts)
```ts
import type { Identity } from "pb.types";
const value = Object.assign({ A: true }, { B: true });
// ^ { A: boolean } & { B: boolean }
type _Result = Identity;
// ^ { A: boolean; B: boolean }
```
### `branch`
- [`branch`](./src/branch.ts)
```ts
import { branch } from "pb.types";
void function example(): string | number | undefined {
if (branch()) {
return "abc";
}
if (branch()) {
return 12345;
}
return undefined;
};
```