Giter Club home page Giter Club logo

typelevel-ts's Introduction

TypeScript compatibility

The stable version is tested against TypeScript 2.9.1+

API

Equals<A, B>

Returns the string literal 'T' if A and B are equal types, 'F' otherwise

Equals<string, string> // "T"
Equals<string, number> // "F"

Omit<A extends object, K extends string | number | symbol>

Extracts a super-type of A identified by its keys K

Omit<{ a: string; b: number }, 'a'> // { b: number }

Overwrite<A extends object, B extends object>

Overwrite<{ a: string; b: number }, { b: boolean }> // { a: string; b: boolean }

Diff<A extends object, K extends keyof A>

Diff<{ a: string; b: number }, 'b'> // { a: string; b?: number }

RowLacks<A extends object, K extends string | number | symbol>

Encodes the constraint that a given object A does not contain specific keys K

declare function f(x: RowLacks<{ a: string; b: number }, 'a'>): void
// $ExpectError
f({ a: 'foo', b: 1 })

Exact<A extends object, B extends A>

declare function f<T extends Exact<{ a: string }, T>>(a: T): void
declare const x: { a: string }
declare const y: { a: string; b: number }
f(x)
// $ExpectError
f(y)

KeysOfType<A extends object, B>

Picks only the keys of a certain type

KeysOfType<{a: string, b: string | boolean, c: boolean, d: string}, string> // "a" | "d"

AnyTuple

declare function f<T extends AnyTuple>(x: T): T
declare const x: [number]
declare const y: [number, string]
declare const z: [number, string, boolean]
declare const t: Array<number>
f(x)
f(y)
f(z)
// $ExpectError
f(t)

DeepReadonly

interface Foo {
  bar: {
    baz: string
    quux: Array<{ barbaz: number }>
  }
}

type ReadonlyFoo = DeepReadonly<Foo>
declare const x: ReadonlyFoo
// $ExpectError
x.bar.quux[1].barbaz = 1

TaggedUnionMember<A extends object, Tag extends keyof A, Value extends A[Tag]>

Extracts the type of a member of a tagged union

type A = { tag: 'A'; a: string }
type B = { tag: 'B'; b: number }
type C = A | B
TaggedUnionMember<C, 'tag', 'A'> // A

RequiredKeys and OptionalKeys

Extracts required or optional keys as a literal type union

type A = { a: string; b: number; x?: string; y?: number }
RequiredKeys<A> // "a" | "b"
OptionalKeys<A> // "x" | "y"

typelevel-ts's People

Contributors

gcanti avatar jakeweary avatar mattiamanzati avatar oliverjash avatar pelotom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.