A TypeScript type manipulation library. It is a types-only library, i.e. it has 0 runtime code.
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.
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>>;
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 }>>
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>;