npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@litert/utils-ts-types

v1.6.0

Published

The static type utilities for TypeScript.

Downloads

315

Readme

LiteRT/Utils - TypeScript Types

Strict TypeScript Checked npm version License node GitHub issues GitHub Releases

The utility functions/classes/constants about helper types for TypeScript.

Requirement

  • TypeScript v5.0.0 (or newer)
  • Node.js v18.0.0 (or newer)

Installation

npm i @litert/utils-ts-types --save

Usage

Type IJsonSafeValue

The IJsonSafeValue type is a TypeScript type that express a JSON safe value, which could be safely passed to JSON.stringify, and may be returned by JSON.parse.

Thus, only the following types are allowed:

  • Basic Types: string, number, boolean, null
  • Array of JSON safe values
  • Object with string keys and JSON safe values

Note that undefined, function, symbol, bigint and other non-JSON safe types are not allowed.

Type IObject

The IObject type is a type stands for any object values, usefully in generic constraints.

And this helps to avoid the ESLint rule @typescript-eslint/ban-types error.

type ISomeType<T extends IObject> = ...;

Type IDict

The IDict is a lite form of Record<string, any>, which is more suitable to express a dictionary object.

const dictOfAny: IDict = {
    key1: 'value1',
    key2: 42,
    key3: true,
};

const dictOfString: IDict<string> = {
    key1: 'value1',
    key2: '42',
    key3: 'true',
};

Type IFunction and IAsyncFunction

The IFunction type is a type stands for any function values, usefully in generic constraints.

type ISomeType<T extends IFunction> = ...;

Type IDeepPartial

The IDeepPartial<T> type is a recursive version of the built-in Partial<T> type. It makes all properties of an object type T optional, including nested properties.

Type IConstructor

The IConstructor type is a type that represents a class constructor function.

class MyClass {};

const ctor: IConstructor<MyClass> = MyClass;

Type IElementOfArray

The IElementOfArray<T> type is a utility type that extracts the element type from an array type T.

type MyArray = string[];

const arr: MyArray = ['a', 'b', 'c'];

const el0: IElementOfArray<MyArray> = arr[0];

Type IMaybeArray

The IMaybeArray<T> type is a utility type that represents a value that can be either a single value of type T or an array of type T.

This type is useful for function parameters or some options that can accept either a single value or multiple values.

interface IOptions {

    tag: IMaybeArray<string>;
}

function processItems(items: IMaybeArray<string>) {

    const itemArray = Array.isArray(items) ? items : [items];
    // ...
}

Type IMaybeAsync

The IMaybeAsync<T> type is a utility type that represents a value that can be either of type T or a Promise that resolves to type T. This type is useful for the return type of functions that can be either synchronous or asynchronous.

function maybeAsync(flag: boolean): IMaybeAsync<string> {
    if (flag) {
        return 'synchronous value';
    } else {
        return Promise.resolve('asynchronous value');
    }
}

Type IfIsAny

The IfIsAny<T, TYes, TNo> type is a conditional type that checks if the type T is any. If T is any, it resolves to TYes; otherwise, it resolves to TNo.

Type IfIsNever

The IfIsNever<T, TYes, TNo> type is a conditional type that checks if the type T is never. If T is never, it resolves to TYes; otherwise, it resolves to TNo.

Documentation

License

This library is published under Apache-2.0 license.