npm.io
0.0.4 • Published 3 years ago

typed-helpers

Licence
MIT
Version
0.0.4
Deps
0
Size
7 kB
Vulns
0
Weekly
0
Stars
2

typed-helpers

npm CircleCI

Typed utils for TypeScript codebases.

Installation

npm i typed-helpers --save

Usage

typedObject.keys()
import { typedObject } from 'typed-helpers';

const planets = {
  earth: 'Earth',
  mars: 'Mars',
  jupiter: 'Jupiter',
} as const;

const nativeKeys = Object.keys(planets);
// string[]

const typedKeys = typedObject.keys(planets);
// ("earth" | "mars" | "jupiter")[]
typedObject.entries()
import { typedObject } from 'typed-helpers';

const planets = {
  earth: 'Earth',
  mars: 'Mars',
  jupiter: 'Jupiter',
} as const;

const nativeEntries = Object.entries(planets);
// [string, "Earth" | "Mars" | "Jupiter"][]

const typedEntries = typedObject.entries(planets);
// ["earth" | "mars" | "jupiter", "Earth" | "Mars" | "Jupiter"][]

License

Open source under the terms of the MIT License.

Maintained by Diogo Capela.

Keywords