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

@shencom/typing

v0.4.0

Published

shencom typescript types

Downloads

59

Readme

@shencom/typing

集成一些类型工具方法,公共接口的请求参数和响应数据类型

install

pnpm add @shencom/typing

# or

yarn add @shencom/typing

Usage

Init

配置 tsconfig

// tsconfig.json
{
  "compilerOptions": {
    "types": ["@shencom/typing"]
  }
}

Basic Usage

import { DeepMutable, Unfurl } from '@shencom/typing';

// ...

Typing

UTILS

  • Unfurl<T>: 展开对象类型

    interface User {
      name: string;
      profile: {
        address: string;
      };
    }
    type User1 = Unfurl<User>;
  • OneOf<T, U>: 类型二选一

    const A: OneOf<{ a: string }, { b: string }> = {
      a: '',
    };
    // or
    const B: OneOf<{ a: string }, { b: string }> = {
      b: '',
    };
    
    // error 不能将类型“{ a: string; b: string; }”分配给类型
    const AA: OneOf<{ a: string }, { b: string }> = {
      a: '',
      b: '',
    };
  • Mutable: 移除 readonly

    interface User {
      readonly name: string;
      readonly age: number;
    }
    
    type User1 = Mutable<User>; // type User1 = { name: string; age: number; }
  • DeepMutable: 递归移除 readonly

    interface User {
      readonly name: string;
      readonly profile: {
        readonly address: string;
      };
    }
    type User1 = DeepMutable<User>; // type User1 = { name: string; profile: { address: string } };
  • DeepParameters<T, Deep=1>: 获取第 N 层函数参数,默认第二层

    const A = (b: number) => {};
    type B = DeepParameters<typeof A>; // [b: number]
    
    const AA = (b: number) => (c: number) => {};
    type BB = DeepParameters<typeof AA>; // [c: number]
    
    const AAA = (b: number) => (c: number) => (d: number) => {};
    type BBB = DeepParameters<typeof AAA, 2>; // [d: number]
  • ReturnPromiseType<T>: 获取函数返回 Promise 泛型的值

    type A = (b: number) => Promise<boolean>;
    
    type B = ReturnPromiseType<A>; // boolean
  • Dictionary<T>: 对象添加索引类型

    const a = {};
    a.a = 1; // 类型“{}”上不存在属性“a”。
    
    const aa: Record<string, any> = {};
    aa.a = 1;

SC

  • SC.API
    • Query: 搜索类型
    • Sorts: 筛选字段
    • IndexQuery: index 接口查询参数类型
    • IndexSorts: index 接口排序参数类型
    • IndexInterface<T>: 分页接口
    • IndexBodyInterface: index 接口参数类型
    • ExportBodyInterface: export 接口参数类型
  • SC.File
    • Info: 文件信息
  • SC.Gis
    • Point: 点位信息
  • SC.OSS
    • Sign: oss 签名
  • SC.User
    • TokenRoot: 令牌信息
    • SysInfo: 系统用户信息
    • WxInfo: 微信用户信息
    • RootInfo: 登录接口返回用户信息类型
    • Info: 系统用户和微信用户并集
  • SC.CSM
    • Category: 栏目类型
    • Articles: 内容类型

第三方

  • 微信 JSSDK