microsoft / microsoft/TypeScript
Prototype assignment should take the type of the initializer and not require a literal
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
This is a feature request based on actual VS customer code.
TypeScript Version: 3.9.2
Search Terms: ES5 class javascript prototype assignment constructor function
Expected behavior: In the example below, the prototype for test.class should include properties from testPrototype.
Actual behavior: Per @sandersn this pattern is recognized in the binder and only uses syntactic information, therefore does not use the type information from testPrototype .
Related Issues: #39167 from same user code. Also #33454 maybe?
Code
var test = {};
test.testPrototype = {
add: function (i) {
}
}
test.class = function (name) {
function getName() {
return name;
}
this.name = getName();
}
test.class.prototype = test.testPrototype;
var t = new test.class("test");
t.name
t.add // EXPECTED: Binds to `add` from the prototype, ACTUAL: doesn't
//
// Same pattern works when a literal is assigned to the prototype:
//
var test2 = {};
test2.class = function (name) {
function getName() {
return name;
}
this.name = getName();
}
// replaced `test.testPrototype` with a literal
test2.class.prototype = {
add: function (i) {
}
};
var t2 = new test2.class("test");
t2.name
t2.add // ACTUAL: `add` bound correctly
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている TypeScript Playground の再現例と、issue に記載された binder の挙動から始め、オブジェクトリテラルのプロトタイプ代入と test.testPrototype からの代入を比較してください。初期化子の型がプロトタイププロパティを提供し、例で t.add が認識される一方、既存のリテラルのケースも引き続き機能すれば、作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100