microsoft / microsoft/TypeScript
Can not specify toString/valueOf methods in object literal
オープン
まだ誰も着手していません。
Bug
Domain: check: Excess Property Checking
Needs Human Review
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 2.5.2
Code
interface X {
name: string
}
const x1: X = {
get name() { return 'x1' },
toString() { return this.name },
// ^^^^^^^^
// Type '{ readonly name: string; toString(): string; }' is not assignable to type 'X'.
// Object literal may only specify known properties, and 'toString' does not exist in type 'X'.
}
const x2: X = {name: 'x2'}
x2.toString = function () { return this.name } // But add `toString` later is allowed.
Expected behavior:
Should allow object literal specify toString, valueOf and all properties exists on Object.prototype, or at least improve the error report to give a workaround (const x: X & Object).
Actual behavior:
See comments in code.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue にある TypeScript 2.5.2 の再現から始め、toString/valueOf に対するオブジェクトリテラルの余分なプロパティチェックと、初期化後に同じメソッドを代入する場合を比較します。Object.prototype のメンバーを受け入れるべきか、それとも診断で示されている X & Object の回避策を提案すべきかを判断します。選択した動作が実装され、回帰テストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100