microsoft / microsoft/TypeScript
Mixin with union as base class
オープン
まだ誰も着手していません。
In Discussion
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 4.1.0-dev.20201015
Search Terms:
Code
abstract class Base {
abstract p1: number;
}
class Derived1 extends Base {
p1 = 1;
p2 = 2;
}
class Derived2 extends Base {
p1 = 1;
p3 = 3;
}
// normally TBase could extend from Base but Base is abstract here, hence the union
function Mixin<TBase extends (new (...params: any[]) => Derived1) | (new (...params: any[]) => Derived2)>(Base: TBase) {
return class extends Base {
p4 = 4;
m() {
console.log(this.p4);
// error: Property 'p1' does not exist on type '(Anonymous class)'.(2339)
// I'd expext the property to be available since both Derived1 and Derived2 have it
console.log(this.p1);
}
};
}
const Derived1WithMixin = Mixin(Derived1);
new Derived1WithMixin().m();
Expected behavior: I'd expect the property p1 to be available in the Mixin since both types in the union have it.
Actual behavior: I get the compiler error error: Property 'p1' does not exist on type '(Anonymous class)'.(2339).
Playground Link: Link
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現例から始め、TypeScript 4.1.0-dev.20201015 で報告されたエラーを検証します。基底コンストラクター型が union である mixin に対するコンパイラーの動作を追跡し、その後、共有プロパティーが利用可能であるべきかを判断します。再現例が期待どおりに動作し、カバレッジによって修正された動作が検証されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100