microsoft / microsoft/TypeScript
Pipe function + `React.memo` returns component with `any` props
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.9.2
Search Terms: generic pipe pipeWith react memo HOC props any
Code
import * as React from 'react';
declare function pipeWith<A, B>(a: A, ab: (a: A) => B): B;
type Props = { foo: number };
declare const MyComponent: React.FunctionComponent<Props>;
// ✅ correct props type
// React.NamedExoticComponent<Props>
const r1 = React.memo(MyComponent);
// ❌ `any` props type
// React.MemoExoticComponent<React.ComponentType<any>>
const r2 = pipeWith(MyComponent, React.memo);
// Workaround
// ✅ correct props type
// React.NamedExoticComponent<Props>
const r3 = pipeWith(MyComponent, (C) => React.memo(C));
Using latest version of @types/react (at the time of writing: 16.9.35).
Expected behavior:
See above.
Actual behavior:
See above.
Playground Link:
https://stackblitz.com/edit/react-ts-4ih6jn
Related Issues:
https://github.com/microsoft/TypeScript/issues/25637, although that was closed as a duplicate of an issue which has since been closed (https://github.com/microsoft/TypeScript/issues/10957), so I decided to post a new issue.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
StackBlitz の再現コードと汎用的な pipeWith の例から始め、React.memo(MyComponent) と pipeWith(MyComponent, React.memo) を比較します。@types/react 16.9.35 の React.memo 宣言に関係する TypeScript の型推論の挙動を確認します。パイプされた結果が any ではなく Props を推論し、直接呼び出しの挙動を維持できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100