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

@iiiristram/ts-type-utils

v1.0.0

Published

- [ts-type-utils](#ts-type-utils) - [`TryOmit<T, K>`](#tryomitt-k) - [`InstanceOf<T>`](#instanceoft) - [`Indexed<T>`](#indexedt) - [`IsAny<T>`](#isanyt) - [`IsObject<T>`](#isobjectt) - [`IsTuple<T>`](#istuplet) - [`Exact<T1, T2

Downloads

39

Readme

ts-type-utils

All types could be used with any value of strictNullChecks option of tsconfig.

TryOmit<T, K>

Omits keys if they exists, otherwise does nothing

type X = TryOmit<{ a: 1; b: 2 }, 'c'>; // { a: 1; b: 2 }
type X = TryOmit<{ a: 1; b: 2; c: 3 }, 'c'>; // { a: 1; b: 2 }

InstanceOf<T>

Returns instance type if constructor provided, otherwise returns never

class Test {}

type X = InstanceOf<typeof Test>; // Test
type X = InstanceOf<{}>; // never

Indexed<T>

Alias for Record<string, T>

IsAny<T>

Returns true if T is any and false otherwise

type X = IsAny<null>; // false
type X = IsAny<undefined>; // false
type X = IsAny<any[]>; // false
type X = IsAny<never>; // false
type X = IsAny<unknown>; // false
type X = IsAny<number>; // false

type X = IsAny<any>; // true

IsObject<T>

Returns true if T describes an object and false otherwise

type X = IsObject<number>; // false
type X = IsObject<any[]>; // false
type X = IsObject<Function>; // false
type X = IsObject<never>; // false
type X = IsObject<unknown>; // false
type X = IsObject<any>; // false
type X = IsObject<null>; // false
type X = IsObject<undefined>; // false

type X = IsObject<object>; // true
type X = IsObject<{}>; // true
type X = IsObject<Indexed>; // true
type X = IsObject<Indexed | Object | {}>; // true
type X = IsObject<Indexed & Object & {}>; // true

IsTuple<T>

Returns true if T is tuple and false otherwise

type X = IsTuple<[any]>; // true
type X = IsTuple<any[]>; // false

Exact<T1, T2>

Returns true if T1 and T2 are the same and false otherwise

type X = Exact<{ x: 1 }, { x: 2 }>; // false
type X = Exact<{ x: 1 }, { x: 1 }>; // true

Known issues:

  • type is not designed to handle function-types
  • type compares optional properties only if they represented in both parameters
type X = Exact<{ x: { y?: string }, { x: { y?: number } }>; // false
type X = Exact<{ x: { y?: string }, { x: {} }>; // true - only T1 has "y" key and it's optional

ExtractByType<T, S>

Picks properties of particular type from the source type

type X = ExtractByType<
    {
        a: any;
        b: number;
        c: unknown;
        d: never;
        e: null;
        f: undefined;
        g?: number;
    },
    number
>; /* {
    b: number;
    g?: number;
} */

ExtractArgs<TFunc>

Returns args type if function type provided, otherwise returns never

type X = ExtractArgs<(a: number, b: string) => void>; // [number, string]

ReplaceReturn<TFunc, TRet>

Replaces return type for provided function type

type X = ReplaceReturn<(a: number, b: string) => void, string>; // (a: number, b: string) => string

ExtractAsyncReturn<TFunc>

Infers return type, and in case a promise returned, infers promise resolution type

type X = ExtractAsyncReturn<(a: number, b: string) => void>; // void
type X = ExtractAsyncReturn<(a: number, b: string) => Promise<void>>; // void

KnownKeys<T>

If T consists of indexed declaration and particular keys, this keys will be returned, if no such keys unknown returned

type X = KnownKeys<{
    [str: string]: any;
    [num: number]: unknown;
    x: number;
    y: string;
}>; // 'x' | 'y'

PickKnown<T>

Creates new type from T by picking known keys

type X = PickKnown<{
    [str: string]: any;
    [num: number]: unknown;
    x: number;
    y: string;
}>; /* {
    x: number;
    y: string;
} */

GetOptionalKeys<T>

Returns keys marked as optional

type X = GetOptionalKeys<{ a: number; b?: undefined; c?: {} }>; // 'b' | 'c'

GetOptional<T>

Creates new type from T by picking optional keys

type X = GetOptional<{ a: undefined; b?: string; c?: undefined }>; // { b?: string; c?: undefined }

GetRequired<T>

Creates new type from T by picking required keys

type X = GetRequired<{ a: null; b?: string; c?: {} }>; // { a: null }

DeepPartial<T>

Recursively makes all keys optional

type X = DeepPartial<{
    s: {
        b: {
            c: number;
        }[];
    };
}>; /*
{
    s?: {
        b?: {
            c?: number;
        }[];
    };
} */

Merge<T1, T2>

Recursively merge two types

type X = Merge<
    {
        a: string;
        b: { c: Array<{ d: number; d2: boolean }> };
        [x: number]: { e?: any };
    },
    {
        b: { c: Array<{ d?: string }>; c2: number };
        [x: number]: { e: boolean };
        f: null;
    }
>; /* {
    a: string;
    b: { c: Array<{ d?: string; d2: boolean }>; c2: number };
    [x: number]: { e: boolean };
    f: null;
} */