Skip to content

Instantly share code, notes, and snippets.

@millsp
Last active April 4, 2020 00:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save millsp/f7f7d18773f79bf0618fb5cd55bd48f8 to your computer and use it in GitHub Desktop.
Save millsp/f7f7d18773f79bf0618fb5cd55bd48f8 to your computer and use it in GitHub Desktop.
import {Object, Tuple, Number} from 'ts-toolbelt'
// Merge two types together
type merge = Object.MergeUp<{name: string}, {age?: number}>
// Update the type of a field
type update = Object.Update<{age: string}, 'age', number>
// Make some fields optional
type optional = Object.Optional<{name: string, age: number}, 'age'>
// Update a type at any depth! (`P` stands for `Path`)
type deepUpdate = Object.P.Update<{a: {b: {c: 1}}}, ['a', 'b', 'c'], 42>
// Concat two tuples together
type concat = Tuple.Concat<[1, 2], [3, 4]>
// Add two numbers together
type add = Number.Plus<'10', '-21'>
// And much more... Check the docs out!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment