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

@mirascript/typed

v0.1.83

Published

Parse MiraScript type definitions and generate TypeScript types / JSON schemas.

Readme

@mirascript/typed

@mirascript/typed 用于解析 MiraScript 类型定义,并可将结果转换为 JSON Schema。

MiraScript 本身不执行编译期或运行时类型检查。该包主要用于文档、提示系统和结构化数据校验场景。

安装

pnpm add @mirascript/typed

快速开始

import { parse, toJSONSchema } from '@mirascript/typed';

const type = parse('record<number>');
console.log(toJSONSchema(type));

console.log(toJSONSchema(parse('(a: number)'), { loose: false }));
console.log(toJSONSchema(parse('(a: number)'), { loose: true }));

类型语法概览

  • 内置类型:nil string number boolean record array
    • array 支持泛型:array<elementType>
    • record 支持泛型:record<valueType>record<keyType, valueType>
  • 交叉类型:typeA & typeB
    • 可选前缀 &
  • 联合类型:typeA | typeB
    • 可选前缀 |
  • 数组类型:type[](同 array<type>
  • 字面量类型:"value" 'value' true false
  • 记录类型:(fieldA: typeA, fieldB: typeB)
    • 可选尾随 ,
    • 空记录:()
    • 匿名字段:(typeA, typeB) (只包含一个匿名字段时尾随 , 不能省略 (type,)
    • 可选属性:(field?: type)
    • 支持使用字符串做字段名以包含特殊字符:("field-name": type)
  • 函数类型:fn(arg: type, ..rest: type) -> returnType
    • 无返回值:fn(arg: type)
    • 无参数:fn() -> returnType
    • 参数类型可省略,默认为 anyfn(a, b: number, ..rest)
    • rest 参数名可省略:fn(..) -> string
    • rest 参数必须是最后一个参数
    • 支持嵌套,例如函数作为参数:fn(arg: number, callback: fn(result: string, error: any) -> any)
    • 支持泛型:fn<T, U>(arg: T) -> U,同名泛型参数在不同作用域中为不同 symbol
    • 顶层函数可携带函数名:fn fnName<T>(arg: T) -> any
  • 字符串插值类型:三种引号均支持 $() 插值
    • 示例:`hello $(type)`"value: $(string | number)"
    • $ 必须紧接 (,否则报错;\$ 可表示字面量 $
  • 元组类型:[typeA, typeB][typeA, ..typeB]
    • 固定长度元组:[number, string, boolean]
    • 带剩余元素的元组:[number, ..string[]](至少一个 number,后跟任意个 string
    • 剩余元素可出现在任意位置:[number, ..string[], boolean][..number[], string]
    • 空元组:[]
    • 嵌套元组:[[number, string], boolean]
  • 反射类型:type(identifier)
    • 获取指定标识符的类型:type(MyVar)
    • 可用于联合类型:type(A) | string

常用导出

  • parse():将类型字符串解析为 Type
  • simplify():在 Type AST 层做归一化和展开,默认开启全部简化;可通过 SimplifyOptions 逐项关闭
  • stringify():将 Type 转换为类型字符串
  • toJSONSchema():将 Type 转换为 JSON Schema
  • TypeKnownTypeRecordTypeFunctionTypeTemplateTypeGenericType 等类型

开发

pnpm --filter @mirascript/typed build
pnpm --filter @mirascript/typed test