microsoft / microsoft/TypeScript
Overload gets lost in mapped type with conditional type
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms: mapped type overload
Code
interface Overloads {
foo(a: string): void;
foo(a: number, b: string): void;
}
/** Converts all properties of an object to Promises and all methods to return Promises */
type ProxiedObject<T> = {
[P in keyof T]: T[P] extends (...args: infer Arguments) => infer R
? (...args: Arguments) => Promise<R>
: Promise<T[P]>
};
declare let x: ProxiedObject<Overloads>;
x.foo("abc"); // Error: [ts] Expected 2 arguments, but got 1. [2554]
x.foo(123, "abc");
Expected behavior:
No error, overload should be maintained.
This makes it impossible to use this pattern with popular types that contain overloads, like Rx Observable pipe()/subscribe().
The ProxiedObject type is used in https://github.com/GoogleChromeLabs/comlink.
Actual behavior:
Overload gets lost, compile error when trying to call the first overload.
Playground Link: link
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供されている Overloads と ProxiedObject の例を使って、リンク先の TypeScript Playground で mapped type の overload 動作を再現します。次に、コンパイラーによる conditional type と mapped type の処理を追跡し、両方の overload 呼び出しに対する回帰テストを追加します。完了条件は、どちらの呼び出しもエラーを生成せず、overload の動作が維持されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100