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

@daben/type-utility

v1.0.0

Published

类型工具库,提供额外的类型工具。提供微信jssdk类型提示

Downloads

12

Readme

类型工具库

用法

yarn add @core/type-utility -D
# or
npm i @core/type-utility -D

在全局 ts 文件中引入,一般是 global.d.ts 或 index.d.ts。如果没有的话在 tsconfig.json 中配置一个。

// in global.d.ts

/// <refrence types="@core/type-utility">
// other type

// in xx.ts
type A = Promise<string>
// type B = string
type B = PromiseType<A>

API

OptionalRequired<T, Keys>

部分字段必填

用法:

interface A {
  a?: string
  b?: number
}

/**
 * type B = {
 *   a: string
 *   b?: number
 * }
 */
type B = OptionalRequired<A, 'a'>

OptionalPartial<T, Keys>

部分字段非必填

用法:

interface A {
  a: string
  b: number
}

/**
 * type B = {
 *   a: string
 *   b?: number
 * }
 */
type B = OptionalPartial<A, 'b'>

DeepRequired<T>

递归必填

用法:

interface A {
  a?: string
  b?: {
    c?: boolean
  }
}

/**
 * type B = {
 *   a: string
 *   b: {
 *     c: boolean
 *   }
 * }
 */
type B = DeepRequired<A>

DeepPartial<T>

递归选填

用法:

interface A {
  a: string
  b: {
    c: boolean
  }
}

/**
 * type B = {
 *   a?: string
 *   b?: {
 *     c?: boolean
 *   }
 * }
 */
type B = DeepPartial<A>

Overwrite<T, U>

重写属性

用法:

interface A {
  a: string
  b: {
    c: boolean
  }
}

/**
 * type B = {
 *   a: string
 *   b: number
 * }
 */
type B = Overwrite<
  A,
  {
    b: number
    c: boolean
  }
>

Assign<T, U>

合并覆盖属性

用法:

interface A {
  a: string
  b: {
    c: boolean
  }
}

/**
 * type B = {
 *   a: string
 *   b: number
 *   c: boolean
 * }
 */
type B = Assign<
  A,
  {
    b: number
    c: boolean
  }
>

PromiseType<T>

获取 Promise 结果类型

用法:

type A = Promise<string>
// type B = string
type B = PromiseType<A>

Intersection<T, U>

取交集

用法:

interface A {
  a: string
  b: number
}

interface B {
  a: string
  c: boolean
}

/**
 * type C = {
 *   a: string
 * }
 */
type C = Intersection<A, B>

Union<T, U>

取并集

用法:

interface A {
  a: string
  b: number
}

interface B {
  a: string
  c: boolean
}

/**
 * type C = {
 *   a: string
 *   b: number
 *   c: boolean
 * }
 */
type C = Union<A, B>

NonNullFilter

特殊类型,解决 array.filter(Boolean)类型无法排除 null,undefined 的情况

用法:

// (0 | 1)[]
;([null, 0, 1, undefined] as const).filter(Boolean as any as NonNullFilter)

TruthyFilter

特殊类型,解决 array.filter(Boolean)类型无法排除 falsy 值的情况

用法:

// 1[]
;([null, 0, 1, undefined] as const).filter(Boolean as any as TruthyFilter)

ValueOf<T>

获取值的联合类型

用法:

interface A {
  a: string
  b: number
  c: boolean
}

// type B = string | number | boolean
type B = ValueOf<A>