Useful Common Typescript Types
This package provides some useful common Typescript types.
This section shows simple usage examples for some of the types.
OmitTyped - type-enforced version of Typescript's built-in Omit.
import { OmitTyped } from '@samhuk/type-helpers'
type A = { foo: string, bar: string, fizz: string, buzz: string }
type B = OmitTyped<A, 'fizz'> // OK
type C = OmitTyped<A, 'notAProp'> // tsc errorIsAny - determines if a type is explicitly any or not.
import { IsAny } from '@samhuk/type-helpers'
type A = IsAny<any> // true
type B = IsAny<1> // falseDictValues - converts a dictionary type to a union of it's values.
import { DictValues } from '@samhuk/type-helpers'
type A = { a: 1, b: 2, c: 3, d: 4 }
type B = DictValues<A> // 1 | 2 | 3 | 4StringKeysOf - converts a dictionary type to a union of it's keys, ensuring that they are all strings. This is useful because keyof will tell typescript that your union will be values of string, number, or symbol, which is quite often not what you want.
import { StringKeysOf } from '@samhuk/type-helpers'
type A = { a: 1, b: 2, c: 3, d: 4 }
type B = StringKeysOf<A> // 'a' | 'b' | 'c' | 'd'Contributions are welcome! See ./contributing/development.md.
Package generated from ts-npm-package-template