@guanghechen/utility-types
TypeScript icon, indicating that this package has built-in type declarations

6.0.0-alpha.0 • Public • Published

@guanghechen/utility-types


Collection of typescript utility types. Borrowing from the repository utility-types.

Usage

Diff

Remove properties that exist in U from T.

import { Diff } from '@guanghechen/utility-types'

type Props = { name: string, age: number, visible: boolean }
type DefaultProps = { age: number }

type RequiredProps = Diff<Props, DefaultProps>
// => { name: string, visible: boolean }

Mutable

Make all properties in T mutable.

import { Mutable } from '@guanghechen/utility-types'

type Props = {
  readonly name: string
  readonly age: number
  readonly visible: boolean
}

type MutableProps = Mutable<Props>
// => { name: string, age: number, visible: boolean }

PickPartial

Make a set of properties by key K become optional from T.

import { PickPartial } from '@guanghechen/utility-types'

type Props = {
  name: string
  age: number
  visible: boolean
}

type PartialProps = PickPartial<Props>
// => { name?: string, age?: number, visible?: boolean }

type PartialProps2 = PickPartial<Props, 'name'>
// => { name?: string, age: number, visible: boolean }

Install

  • npm

    npm install --save-dev @guanghechen/utility-types
  • yarn

    yarn add --dev @guanghechen/utility-types

Usage

Related

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @guanghechen/utility-types

      Weekly Downloads

      397

      Version

      6.0.0-alpha.0

      License

      MIT

      Unpacked Size

      32.2 kB

      Total Files

      8

      Last publish

      Collaborators

      • lemonclown