Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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>;
```