百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-docgen-typescript

> 编程语言
开源

一个简单的解析器,用于 React 属性,而不是 propTypes 中定义的 TypeScript 属性。

1.3K stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个简单的解析器,用于 React 属性,而不是 propTypes 中定义的 TypeScript 属性。

React-docgen-TypeScript

一个简单的解析器,用于 React 属性,而不是 propTypes 中定义的 TypeScript 属性。 可以与 React Styleguidist 结合使用。

安装

bash
npm install --save-dev react-docgen-typescript

使用方法

要解析文件中的 docgen 信息,请使用 parse 函数。

typescript
const docgen = require("react-docgen-typescript");

const options = {
  savePropValueAsString: true,
};

// Parse a file for docgen info
docgen.parse("./path/to/component", options);

如果您想自定义 TypeScript 配置或 docgen 选项,此包提供了多种创建自定义解析器的方式。

typescript
const docgen = require("react-docgen-typescript");

// Create a parser with the default typescript config and custom docgen options
const customParser = docgen.withDefaultConfig(options);

const docs = customParser.parse("./path/to/component");

// Create a parser with the custom typescript and custom docgen options
const customCompilerOptionsParser = docgen.withCompilerOptions(
  { esModuleInterop: true },
  options
);

// Create a parser with using your typescript config
const tsConfigParser = docgen.withCustomConfig("./tsconfig.json", {
  savePropValueAsString: true,
});

React Styleguidist 集成

在 styleguide.config.js 中添加以下行:

javascript
module.exports = {
  propsParser: require("react-docgen-typescript").withDefaultConfig([
    parserOptions,
  ]).parse,
};

或者如果您想使用自定义的 tsconfig 文件

javascript
module.exports = {
  propsParser: require("react-docgen-typescript").withCustomConfig(
    "./tsconfig.json",
  ).parse,
};

选项

propFilter

propFilter 选项允许您在生成文档时忽略某些属性。您可以提供包含一些我们预先配置的过滤器的对象:

[parserOptions]

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言