0.2.0 • Published 2 years ago

@nidomiro/ts-type-utils v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ts-type-utils

npm version

A library containing utilities for typescript.

Content

ModifyTypeOfProperty

Modifies the type of existing properties.

Correct:

type A = {
	a: string
	b: string
}
type ModA = ModifyTypeOfProperty<A, { b: number }>
/*
ModA = {
    a: string,
	b: number,
}
 */

Incorrect:

type A = {
	a: string
	b: string
}
type ModA = ModifyTypeOfProperty<A, { c: number }>
/*
Error:
TS2559: Type '{ c: number; }' has no properties in common with type 'Partial{ a: unknown; b: unknown; }>'.
 */

isNonNilObject

Checks if value is of type 'object' and not (null or undefined)

const a: {} | null | undefined = {}
if (isNonNilObject(a)) {
	// type: a: Record<string, unknown>
}

Development

Building

Run nx build ts-type-utils to build the library.

Running unit tests

Run nx test ts-type-utils to execute the unit tests.

Publish

Make sure you are logged into npm.

Run nx publish ts-type-utils --tag latest --ver x.x.x to publish to npm.