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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-tooltype

v1.0.1

Published

Common TypeScript generic tool types at work

Readme

ts-tooltype

Common TypeScript generic tool types at work

主要整理了工作中常用的 TypeScript 类型体操工具类型

Install

npm i -D ts-tooltype

Number 相关

NumberToStr

将数字转为字符串

type Test = NumberToStr<999>; // "999"

GenerateNumArr

从 0 开始自增 1,得到指定长度的数组,由于 TS 递归限制最大只能传 999

type Test = GenerateNumArr<3>; // [0, 1, 2]

RangeNumber

生成指定整数范围的联合类型

type Test = RangeNumber<0, 5>; // 0 | 1 | 2 | 3 | 4 | 5

Object 相关

DeepMerge

深合并对象类型

type Test = DeepMerge<{ a: { a: 1; b: 3 } }, { a: { a: 3; c: 3 } }>; // {a: { a: 3; b: 3; c: 3; } }

SelectTypeKey

获取对象中指定类型的 key 的联合类型

type Test = SelectTypeKey<{ a: 1; b: true; c: 3 }, number>; // 'a' | 'c'

PickKeyType

返回指定“类型”的 key 组成的对象

type Test = PickKeyType<{ a: 1; b: true; c: 3 }, number>; // { a: 1; c: 3; }

OmitKeyType

剔除指定“类型”的 key 后组成的对象

type Test = OmitKeyType<{ a: 1; b: true; c: 3 }, number>; // { b: true; }

PickPartial

指定 K 为可选,K 可传联合类型表示指定多个 key 可选

type Test = PickPartial<{ a: 1; b: 2; c: 3 }, "a" | "b">; //{a?: 1, b?: 2, c: 3}

String 相关

StringToNumber

将字符串转为数字,只能转换 0 - 999 的整数

type Test = StringToNumber<"999">; // 999

Union 相关(联合类型)

UnionToIntersection

联合类型转为交叉类型,利用的是 extends 分发的特性结合在函数参数发生的逆变且被提取为同一类型参数名后,则该类型参数会变为交叉类型的特性

type Test = UnionToIntersection<{ a: 1 } | { b: 2 }>; // {a: 1} & {b: 2}

UnionToTuple

联合类型转为元组类型

type Test = UnionToTuple<"2" | "1" | "3">; // ["2", "1", "3"]

IsUnion

判断一个类型是不是联合类型,利用元组包裹联合类型阻止被分发去判断

type Test = IsUnion<1 | 2 | 3>; // true