Skip to content

Better error messages for converting symbols to strings #25870

Closed

Description

Starting

declare let x: symbol;

// [ts] Type 'symbol' cannot be converted to type 'string'.
`${x}`;

// [ts] The '+' operator cannot be applied to type 'symbol'.
"" + x;

I believe with TypeScript 2.9, we started erroring on the former operation (#22251). When upgrading to 2.9 with Yehuda Katz (@wycats), we got these error messages and it became clear that for most users it wouldn't immediately be obvious why this was an error.

Yehuda Katz (@wycats) had the recommendation that we suggest using String(x):

Type 'symbol' cannot be converted to type 'string'. Consider wrapping this expression in 'String(...)'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions