microsoft / microsoft/TypeScript
Parameters<T> and ReturnType<T> limitation
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.9.2
Search Terms:
Generic Method Extend Parameters ReturnType
Code
export class Test {
myMethod(): string {
return "42";
}
myMethod2(a: string): string {
return "42" + a;
}
// Works ---
override<M extends keyof this>(method: M, newFunc: this[M]) {
}
// Works ---
override2<M extends keyof this>(method: M, newFunc: (...args: Parameters<this["myMethod2"]>) => ReturnType<this["myMethod2"]>) {
}
// Fails ---
override3<M extends keyof this>(method: M, newFunc: (...args: Parameters<this[M]>) => ReturnType<this[M]>) {
}
}
const test = new Test();
test.override("myMethod2", a => "xxx");
test.override2("myMethod2", a => "xxx");
test.override3("myMethod2", a => "xxx");
Expected behavior:
I would expect override3 to compile and be equivalent to override + override2 (when M == "myMethod2")
Actual behavior:
override3 causes syntax error:
Type 'this[M]' does not satisfy the constraint '(...args: any) => any'.
Type 'this[keyof this]' is not assignable to type '(...args: any) => any'.
Type 'this[string] | this[number] | this[symbol]' is not assignable to type '(...args: any) => any'.
Type 'this[string]' is not assignable to type '(...args: any) => any'.
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、T が this[M] でインデックス付けされたジェネリックの場合に、コンパイラーが Parameters と ReturnType をどのように処理するかを調べてください。override3 の例が myMethod2 に対して期待される推論でコンパイルされ、その動作が適切なコンパイラーテストでカバーされれば、issue は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100