一个简单的解析器,用于 React 属性,而不是 propTypes 中定义的 TypeScript 属性。
一个简单的解析器,用于 React 属性,而不是 propTypes 中定义的 TypeScript 属性。
一个简单的解析器,用于 React 属性,而不是 propTypes 中定义的 TypeScript 属性。 可以与 React Styleguidist 结合使用。
npm install --save-dev react-docgen-typescript要解析文件中的 docgen 信息,请使用 parse 函数。
const docgen = require("react-docgen-typescript");
const options = {
savePropValueAsString: true,
};
// Parse a file for docgen info
docgen.parse("./path/to/component", options);如果您想自定义 TypeScript 配置或 docgen 选项,此包提供了多种创建自定义解析器的方式。
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,
});在 styleguide.config.js 中添加以下行:
module.exports = {
propsParser: require("react-docgen-typescript").withDefaultConfig([
parserOptions,
]).parse,
};或者如果您想使用自定义的 tsconfig 文件
module.exports = {
propsParser: require("react-docgen-typescript").withCustomConfig(
"./tsconfig.json",
).parse,
};propFilterpropFilter 选项允许您在生成文档时忽略某些属性。您可以提供包含一些我们预先配置的过滤器的对象:
[parserOptions]
暂无开放 Issues,或尚未同步最近议题。