ts-powertypes
v0.0.5
Published
Collection of typescript types
Downloads
16
Maintainers
Readme
ts-powertypes
Collection of typescript types
This package is work in progress and semantic versioning is not yet guaranteed. If you use this package, please make sure to set explcit version number in your package json.
Install
npm install ts-powertypes
Usage
import type { Flatten } from 'ts-powertypes';
type Book = {
title: string;
chapters: {
title: string;
content: Record<string, string>;
}[];
};
type FlatBook = Flatten<Book>;
/*
{
title: string;
[x: `chapters.${number}.title`]: string;
[x: `chapters.${number}.content.${string}]: string;
}
*/
Api
Object types
Primitive
union of all primitive typescript typesKey
union of primitive types that can be used as object keysElementType
gets the type of the elements of an Array, Map or RecordKeyOf
union of the keys of an objectValueOf
union of the value types of an objectObjectKeys
strong type for the return type ofObject.keys()
ObjectValues
strong type for the return type ofObject.values()
ObjectEntries
strong type for the return type ofObject.entries()
Split
splits a string constant on a given separatorJoin
joins a string constant on a given separatorFlatten
flattens an object structureObjectPaths
union of all key paths of an objectValuesAtPath
value type of an object at a given patchIsAny
evaluates totrue
if the given type isany
, elsefalse
Version history
See changelog