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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@memo28/types

v1.1.8

Published

type helper

Downloads

35

Readme

@memo28/types

  • 基本类型
 type int = number;
 type bool = boolean;
 type str = string;
 type obj = object;
 /**
 * @description 指定obj的value类型
 */
 type objWithValue<T> = { [key: string]: T };
  • 函数类型
/**
 * @description define normal function type
 */
export declare type fn<P extends any[] = any, R = unknown> = (...args: P) => R

/**
 * @description define promise function type
 */
export declare type promiseFn<P extends any[] = any, R = unknown> = (...args: P) => Promise<R>

/**
 * @description merge define normal function and define promise function type
 */
export declare type mergeFnWithPromiseFn<T = unknown, P extends any[] = any, isP extends boolean | undefined = undefined> = isP extends undefined
  ? fn<P, T> | promiseFn<P, T>
  : isP extends true
  ? promiseFn<P, T>
  : fn<P, T>
  • 对象类型
/**
 * @description 获取对象的所有key
 */
export type getObjValues<V = object> = V[keyof V]
  • 插件类型
/**
 * @description 自动装配,通常使用在读写配置场景中
 */
export interface AutomaticAssembly<T = object, R = unknown> {
    config: T | undefined
    readConfiguration(res?: T): this
    getAssemblyCompleted(): R
}
  • 验证类型
export declare type Expect<T extends true> = T

export declare type IsFalse<T extends false> = T

/**
 * @description 0 extends 1 永远返回false, (0 不可分配给 1), 因此0 extends (1 & T) 也不会满足,因为 ( 1 & T) 比 1 的类型范围 更窄 .
 * 但是当T 是 any 时 , 由于 any 是故意不健全的类型(顶级类型), 并且充当了几乎所有其他类型的超类型和子类型, 因此比较any时其他类型会被忽略 就变成了 0 extends any , 自然返回 true.
 * 需要注意的时这仅仅适用 strictNullChecks 启用 (默认启用)
 * @see https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
 */
export declare type IsAny<T> = 0 extends 1 & T ? true : false

/**
 * @description 这是一个创造性的使用条件类型的可分配行规则的解决方案. 它依赖于在未知时被延迟推导的条件类型T ,延迟类型条件的可分配依赖于内部 isTypeIdenticalTo 检查,这仅是用于 1. 两种条件类型具有相同的约束 2. 两个条件的真假分支是同一类型
 * @see https://github.com/Microsoft/TypeScript/issues/27024
 */
export declare type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false

export declare type Extends<E, V> = E extends V ? true : false