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-metatype

v0.8.0-alpha

Published

define type in runtime by typescipt

Downloads

8

Readme

Typescript的运行时类型系统

将运行时类型定义,校验和编辑时类型提示检测联系起来,基于ts-metacode实现
主要功能(打勾表示已经实现):

  • [x] 定义运行时类型
  • [x] 在开发时提供等同于Typescript类型定义的提示功能(类型生成)
  • [x] 使用typedef对value进行校验
    • [x] validate函数提供的结果可以被编辑器用作类型跟踪
  • [ ] 支持可扩展的类型定义(自定义class)
  • [ ] 扩展类型定义
    • [ ] 支持在类型定义中添加默认值
    • [ ] 支持在类型定义中添加Example表(kv对),并支持使用函数直接获取
    • [ ] 支持动态对类型定义添加Example值,并保持类型定义的功能不变
    • [ ] 对添加Example后或Default后的类型定义,支持将添加的值的信息(如key名)添加到类型定义中,并提供编辑时支持
    • [ ] 对不同模态的类型定义实现兼容

Example

以下为已实现功能的测试

静态类型获取

// 测试部分
const tp = {
  a: Object,
  b: String,
  c:Number,
  h: {
    c: Object
  },
  k: multi([Object, Array, String]),
  // default this declare a type of (number|object)[]
  s: [Object, Number],
  sss:ANY
};


type MyType = TypeOf<typeof tp>;

// 此时MyType的类型和直接使用interface或type关键字定义的类型一致,支持编译器提示

编译时数据类型检测

const tt = {
  a: Object,
  b: String,
  c: {
    d:Number
  }
}
//! 以下代码会报错 d的类型错误,应该为number
const v = value(tt, {
  a: {t:""},
  b: "",
  c: {
    d:"s"
  }
})

运行时类型校验

const tt = {
  a: Object,
  b: String,
  c: {
    d:Number
  }
}
//以下代码得到true ,可尝试修改其中数据类型,查看校验结果
console.log(validate(tt, {
  a: {t:""},
  b: "",
  c: {
    d:100
  }
}))

问题

  • [ ] object类型拦截问题,所有不在基本类型表中的类型会被映射为object,限制了可扩展性,这有赖于ts-metacode包的更新改进映射功能
  • [ ] ANY类型的定义问题,可能存在隐患({}别名产生的问题)