reactjs / reactjs/react-docgen
Order of intersection types leads to non-deterministic results
オープン
まだ誰も着手していません。
question
- 主要言語
- TypeScript
- スター
- 3.8k
- フォーク
- 316
- 平均マージ
- 5時間 7分
- マージ済み PR(30日)
- 4
説明
The following:
import React from 'react';
type Props = { children: React.ReactNode; } & { children?: React.ReactNode; }
const Component = ({ children }: Props) => {
return <div>{children}</div>
}
export default Component;
Gives these results:
{
"description": "",
"displayName": "Component",
"methods": [],
"props": {
"children": {
"required": false,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
"description": ""
}
}
}
As you can see, children are NOT required, however, if I switch the order of the intersection type:
import React from 'react';
type Props = { children?: React.ReactNode; } & { children: React.ReactNode; }
const Component = ({ children }: Props) => {
return <div>{children}</div>
}
export default Component;
Then the result is different, with children now being required...
{
"description": "",
"displayName": "Component",
"methods": [],
"props": {
"children": {
"required": true,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
"description": ""
}
}
}
Is this expected behaviour?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、報告にある2つの TypeScript の intersection の例で問題を再現し、生成された props メタデータを比較します。ドキュメント出力が、それぞれの intersection の順序について children が必須かどうかをどのように判定しているかを追跡します。両方の順序で、必須性について同じ正しい結果が得られれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- documentation
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100