reactjs / reactjs/react-docgen
Typescript: Component props not parsed with 'call signature' type
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 3.8k
- フォーク
- 316
- 平均マージ
- 5時間 7分
- マージ済み PR(30日)
- 4
説明
Description
In Typescript, it's possible to type a function using a call signature.
For example, this is valid TS:
interface A {
foo: string;
}
type FnType = (props: A) => string;
const Fn1: FnType = (props) => props.foo; // valid
const Fn2 = (props: A) => props.foo; // also valid
See example in TS Playground
In the above example, react-docgen generates types for Fn2, but does not generate types for Fn1 which is defined with a call signature type.
Expected Behavior
This code:
// component.tsx
interface A {
foo: string;
}
type ComponentType = (props: A) => JSX.Element;
const Component1: ComponentType = (props) => <div />; // does not include generated props
const Component2 = (props: A) => <div />; // includes generated props
Produces this output:
[
{
"description": "",
"displayName": "Component1",
"methods": [],
"props": {
"foo": {
"required": true,
"tsType": {
"name": "string"
},
"description": ""
}
}
},
{
"description": "",
"displayName": "Component2",
"methods": [],
"props": {
"foo": {
"required": true,
"tsType": {
"name": "string"
},
"description": ""
}
}
}
]
Actual Behavior
The same code produces this output:
[
{
"description": "",
"displayName": "Component1",
"methods": []
},
{
"description": "",
"displayName": "Component2",
"methods": [],
"props": {
"foo": {
"required": true,
"tsType": {
"name": "string"
},
"description": ""
}
}
}
]
Steps to Reproduce
Paste the .tsx sample code from the "Expected Behavior" section in the react-docgen playground with Language set to Typescript.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Language を Typescript に設定した状態で react-docgen playground の .tsx サンプルを再現し、Component1 と Component2 を比較します。call-signature type が割り当てられたコンポーネントの TypeScript パースのエントリーポイントを追跡します。Component1 に Component2 と同じ foo prop メタデータが含まれれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- documentation, tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100