[TS] parse returns props without type field.

オープン
#470 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
react, typescript

調査の方向性

提供された TSX 入力を parse(context.code, ...) エントリーポイント経由で再現し、rawReactDocs.props を調べます。次に、返された prop メタデータを期待される type フィールドと比較します。パーサーの出力でそのフィールドが省略される理由を追跡し、この例で修正されたメタデータを示すカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

説明

typescript

the input code

import React from 'react';
import './button.css';

export interface ButtonProps {
  /**
   * Is this the principal call to action on the page?
   */
  primary?: boolean;
  /**
   * What background color to use
   */
  backgroundColor?: string;
  /**
   * How large should the button be?
   */
  size?: 'small' | 'medium' | 'large';
  /**
   * Button contents
   */
  label: string;
  /**
   * Optional click handler
   */
  onClick?: () => void;
}

/**
 * Primary UI component for user interaction
 */
export const Button: React.FC<ButtonProps> = ({
  primary = false,
  size = 'large',
  backgroundColor,
  label,
  ...props
}) => {
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
  return (
    <button
      type="button"
      className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
      style={{ backgroundColor }}
      {...props}
    >
      {label}
    </button>
  );
};

the parse code

     const rawReactDocs = parse(context.code, null, null, {
            filename: context.fileName, //path.resolve(),
            babelrc: false,
        });

        console.log("rawReactDocs", rawReactDocs)

        const rawProps = rawReactDocs.props || {};

        const props = Object.keys(rawProps)
            .filter(name => name !== "children")
            // .filter(name => rawProps[name].type || rawProps[name].tsType || rawProps[name].flowType)
            .map(name => ({ name, value: rawProps[name] }));
        console.log("props", props)

image

主要言語
TypeScript
スター
3.8k
フォーク
316
平均マージ
3時間 28分
マージ済み PR(30日)
6

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

reactjs/react-docgen のほかの issue

reactjs/react-docgen の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。