microsoft / microsoft/TypeScript
TypeScript unable to infer types properly between interfaces and overloaded methods.
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Bug Report
In all versions of TS I can find, there's no way to mark certain call patterns of a method as deprecated while maintaining inference with certain interfaces. If an interface is split out into different overloads so certain overloads can be deprecated, then it breaks inference in some cases.
🔎 Search Terms
I'm not sure what to search for here. Interfaces?
🕗 Version & Regression Information
- All versions
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Observer<T> {
next(value: T): void;
error(error: any): void;
complete(): void;
}
interface Unsubscribable {
unsubscribe(): void;
}
interface Subscribable<T> {
subscribe(observer?: Partial<Observer<T>>): Unsubscribable;
}
class Observable<T> implements Subscribable<T> {
/////////////////////////////////////////
// Valid call pattern
/////////////////////////////////////////
subscribe(observerOrNext?: Partial<Observer<T>> | ((value: T) => void)): Unsubscribable;
//////////////////////////////////////////
// Deprecated call patterns
//////////////////////////////////////////
/**
* @deprecated This call pattern is going away
*/
subscribe(next: null | undefined, error: null | undefined, complete: () => void): Unsubscribable;
/**
* @deprecated This call pattern is going away
*/
subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Unsubscribable;
/**
* @deprecated This call pattern is going away
*/
subscribe(next: (value: T) => void, error: null | undefined, complete: () => void): Unsubscribable;
/**
* @deprecated This call pattern is going away
*/
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Unsubscribable;
////////////////////////////////////////////
// Impl
////////////////////////////////////////////
subscribe(...args: any[]): Unsubscribable {
return {
unsubscribe() {}
};
}
}
function somethingThatTakesSubscribable<T>(arg: Subscribable<T>): T {
return null!;
}
/////////////////////////////////////
// Our failed expectation here
// (it's unknown)
/////////////////////////////////////
const result = somethingThatTakesSubscribable(new Observable<number>()); // $ExpectType number
🙁 Actual behavior
result is unknown above.
🙂 Expected behavior
result would be number.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground から始め、somethingThatTakesSubscribable に渡された Observable の推論結果を再現してください。分割された overload(非推奨のシグネチャを含む)が Subscribable とどのように比較されるかを調査してください。同じ例で result が unknown ではなく number と推論され、報告された overload パターンの coverage があることが完了条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100