Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikea/ts-types
A TypeScript Types Manipulation Library
https://github.com/mikea/ts-types
types typescript typescript-library
Last synced: about 2 months ago
JSON representation
A TypeScript Types Manipulation Library
- Host: GitHub
- URL: https://github.com/mikea/ts-types
- Owner: mikea
- License: other
- Created: 2018-06-23T23:16:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T12:28:13.000Z (over 1 year ago)
- Last Synced: 2024-10-14T18:32:12.114Z (3 months ago)
- Topics: types, typescript, typescript-library
- Language: TypeScript
- Size: 124 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-types
A TypeScript type manipulation library. It is a types-only library, i.e. it has 0 runtime code.
## Predicates
Predicates are types that are resolved to true or false:
```typescript
type P1 = IsNotNull;
type P2 = Or, IsString>;
```Predicate combinators are defined in [`Predicates.ts`](./src/Predicates.ts).
Predicates for primitive types are defined in [`PrimitiveTypes.ts`](./src/PrimitiveTypes.ts).Type equality predicate `Eq` can be used with assertions to test type results.
## Assertions
Predicate value can be asserted during compilation time:
```typescript
let _assert_null = AssertTrue>;
// user-defined predicates
let _assert_p1 = AssertTrue>;
let _assert_p2 = AssertFalse>;
```## Objects Manipulation
Pick or reject properties of a given type:
```typescript
interface Person { name: string; age: number; }type StringProps = PropertiesOfType;
let _assert_props = AssertTrue>
```## Type Tags
Store type information in values:
```typescript
type Descriptor = { name: string } & WithTag<"t", T>;
const stringDescription: Descriptor = { name: "string" }; // no new storage
let t: GetTag<"t", typeof stringDescription>;
```