microsoft / microsoft/TypeScript

Result of `Object.create(null)` may be passed to template literal

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

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript Version: 3.5.1

Search Terms: template string, template literal, Object.create(null)

Code

`${Object.create(null)}`

Expected behavior: TypeError, as the object passed to the template string has no toString method in the prototype chain (as it has no prototype chain at all).

Actual behavior: Everything goes well in the compiler, but JavaScript reports runtime error (ex. TypeError: Cannot convert object to primitive value in Chrome).

Playground Link: https://www.typescriptlang.org/play/index.html#code/AYEg3g8gRgVgpgYwC4DoECc4EMlwBQB2ArgDYkCUAvsEA

Related Issues:
https://github.com/microsoft/TypeScript/issues/30239
https://github.com/microsoft/TypeScript/issues/1108

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

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

はじめの一歩

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

調査の方向性

Playground の再現例 ${Object.create(null)} から始め、コンパイラーがテンプレートリテラルで使用されるオブジェクトをどのように検査するかを追跡します。プロトタイプチェーンに toString メソッドがないオブジェクトに対して意図された診断を特定し、コンパイラーがそれを報告すると同時に、有効なテンプレートリテラルのケースが維持されることを確認します。

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

評価

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

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

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