@guanghechen/utility-types
v6.0.0-alpha.0
Published
Collection of typescript utility types
Downloads
962
Readme
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