Skip to content

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

Open
@erykpiast

Description

@erykpiast

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:
#30239
#1108

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions