@faulty/ts-docs-type-renderer

中文文档
0.3.2发布于 2023/11/30ISCCommonJS近 30 天下载 15.2万

Render type signatures from documentation created by @faulty/ts-docs-loader.

原始使用文档

ts-docs-type-renderer

Render a ts-docs node tree into a type signature using hast.

The resulting hast tree can be rendered by any hyperscript-compatible framework (i.e., JSX-like, like React, Vue, or others).

The rendered tree is annotated with class names for each token so that they can be highlighted accordingly, and links include a data-link attribute to be able to render popovers with more information about them.

Usage

Directly render a type to a hast tree by using TypeRenderer and supplying the doc node:

import {TypeRenderer} from '@faulty/ts-docs-type-renderer';

const renderer = new TypeRenderer(links, renderOptions);
const result = renderer.render(typeNode);

Then convert the hast tree into the appropriate structure for the framework, e.g. for React:

import * as React from 'react';
import {toH} from 'hast-to-hyperscript';

return toH(React.createElement, result);

For React, there's a convenience component to take care of this automatically:

import {Type, TypeContext} from '@faulty/ts-docs-type-renderer/react';

<TypeContext.Provider links={links}>
  <Type type={typeNode} />
</TypeContext.Provider>

版本与发布记录

@faulty/ts-docs-type-renderer 共发布 7 个版本,首次发布于 2023/09/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.2latest2023/11/302 年前
0.3.02023/09/183 年前
0.2.02023/09/183 年前
0.1.32023/09/163 年前
0.1.22023/09/163 年前
0.1.12023/09/163 年前

关于 @faulty/ts-docs-type-renderer 的常见问题

@faulty/ts-docs-type-renderer 是什么?

Render type signatures from documentation created by @faulty/ts-docs-loader.

如何安装 @faulty/ts-docs-type-renderer?

在项目目录运行 npm install @faulty/ts-docs-type-renderer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>= 16.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@faulty/ts-docs-type-renderer 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/faulty__ts-docs-type-renderer 是否存在。

@faulty/ts-docs-type-renderer 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@faulty/ts-docs-type-renderer 可以商用吗?

@faulty/ts-docs-type-renderer 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@faulty/ts-docs-type-renderer 的下载量有多少?

根据 npm 官方下载统计,@faulty/ts-docs-type-renderer 在 2026/10/15 – 2026/11/13 这 30 天内被下载 152,173 次,日均约 5,072 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@faulty/ts-docs-type-renderer 还在维护吗?

最新版本 0.3.2 发布于 2023/11/30(2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/09/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。