microsoft / microsoft/TypeScript

No excess property error for computed property

オープン
#36,920 コメント 7 件 リアクション 7 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

TypeScript Version: 3.7.5 and 3.9.0-dev.20200220

Search Terms: excess property, computed property, index signature

Code

interface Foo {
	a: string;
} 

const bar: Foo = {
	a: "",
	z: "" // error, excess prop
}

const baz: Foo = {
	a: "",
	["Z".toLowerCase()]: "" // this is okay I guess?
}

Expected behavior:
The computed property in the definition of baz should maybe produce an excess property error, since Foo has no string index signature and "Z".toLowerCase() is only known to be a string.

Actual behavior:
The computed property is allowed.

Playground Link: Here

Related Issues: #22427

This issue is a re-opening of #22427, which was marked as a bug and closed as "fixed", but I don't see an actual fix referenced anywhere in that issue and the behavior described in that issue persists. Any ideas? Thanks!

There's an SO question asking this, which brought me to #22427, which has me scratching my head 😕.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue にある TypeScript Playground の再現から始め、計算プロパティのケースと直接的な余剰プロパティのケースを比較してください。関連する issue #22427 を読んで以前の議論を理解してください。期待される余剰プロパティの動作が解決されるか、意図した動作が更新されたコンパイラテストによって文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。