microsoft / microsoft/TypeScript
Interface merging for any property names does not allow type narrowing
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 4.1.0-dev.20201002
Search Terms: interface merging merge object any name subsequent property declarations
Code
interface PropsContainer {
props: {
[propName: string]: any;
}
}
interface PropsContainer {
props: {
[propName: string]: any;
specialProp: string;
}
}
Expected behavior:
This should be allowed. The merged interface should result in a type with props that have any prop name as any except for specialProp which is a string.
This would be useful in a case where a third party library (such as @types/react-test-renderer) declare an object type with { [propName: string]: any } syntax, but you want to narrow the value of the property for specific types via interface merging.
Note that even { specialProp?: any, [propName: string]: any } is not allowed even though the types are functionally identical in this case.
Actual behavior:
This results in a Subsequent property declarations must have the same type.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、マージされた 2 つの PropsContainer 宣言について診断を確認します。次に、後続のプロパティ宣言とインデックスシグネチャに対する型チェックの経路を追跡します。示されたマージが受け入れられ、specialProp が string に絞り込まれ、既存の互換性のない再宣言が引き続き拒否されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100