microsoft / microsoft/TypeScript
Module augmentation allows non-identical type parameters as long as there are defaults, but doesn't pass them
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
- module augmentation
- callback generic type
🕗 Version & Regression Information
Currently using typescript 5.1.6, but AFAIK this behavior was the same in previous versions. This also occurs on the Nightly.
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics (and the rest of the FAQ)
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Chainable<Subject = any> {
within(fn: (prevSubject: Subject) => Chainable<Subject>): Chainable<Subject>;
}
interface Chainable<Subject = any, ExtraType = undefined> {
within(fn: (prevSubject: Subject, extra: ExtraType) => Chainable<Subject>): Chainable<Subject, ExtraType>;
}
interface ChainableLike<Subject = any, ExtraType = undefined> {
within(fn: (prevSubject: Subject) => Chainable<Subject>): Chainable<Subject>;
within(fn: (prevSubject: Subject, extra: ExtraType) => Chainable<Subject>): Chainable<Subject, ExtraType>;
}
type ChainableWithSecondType = Chainable<string, string>;
type Wrong = ChainableWithSecondType['within'];
type Correct = ChainableLike<string, string>['within'];
🙁 Actual behavior
If you omit the default on the added generic ExtraType, you get an error: All declarations of 'Chainable' must have identical type parameters. But when there's a default, it allows the type parameters to be different, but doesn't properly infer types.
Typescript does not produce any errors, but when you mouseover Wrong, it shows the type of extra to be ExtraType.
🙂 Expected behavior
Either TS should completely ban adding an optional extra type parameter, or it should properly infer type (i.e. mousing over Wrong should produce the same as mousing over Correct)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先の TypeScript Playground を使って動作を再現し、提示された module-augmentation の例にある Wrong 型と Correct 型を比較してください。追加されたパラメーターにデフォルト値がある場合に、コンパイラーが異なるジェネリックパラメーターリストをどのように検査するかを追跡し、その後、報告された動作のカバレッジを追加して、オプションの追加パラメーターが一貫して拒否されるか推論されることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100