Skip to content

mikea/ts-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

type P1<T> = IsNotNull<T>;
type P2<T> = Or<P1<T>, IsString<T>>;

Predicate combinators are defined in Predicates.ts. Predicates for primitive types are defined in PrimitiveTypes.ts.

Type equality predicate Eq<X, Y> can be used with assertions to test type results.

Assertions

Predicate value can be asserted during compilation time:

let _assert_null = AssertTrue<IsNull<null>>;
// user-defined predicates
let _assert_p1 = AssertTrue<P1<boolean>>;
let _assert_p2 = AssertFalse<P2<null>>;

Objects Manipulation

Pick or reject properties of a given type:

interface Person { name: string; age: number; }

type StringProps = PropertiesOfType<Person, string>;
let _assert_props = AssertTrue<Eq<StringProps, { name: string }>>

Type Tags

Store type information in values:

type Descriptor<T> = { name: string } & WithTag<"t", T>;
const stringDescription: Descriptor<string> = { name: "string" }; // no new storage
let t: GetTag<"t", typeof stringDescription>;

About

A TypeScript Types Manipulation Library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages