Skip to content

Feature Request: + operator should join non-string types if .toString() method exists #2991

Description

@JairusSW

Feature suggestion

I find it frustrating that both the left and right sides of a String.concat/+ operator cannot join, for example, string and i32.
In JavaScript, it

  1. Checks to see if the right side of the binary expression is a string
  2. If not, it then checks if the right side has a .toString(): string method
  3. If so, it calls it and concatenates left+right.toString()

Would be quite simple to implement. For example, this would probably work:

exportclassString{
...
@operator("+")_concat<T>(left: string,right: T): string{if(!isDefined(right.toString()))ERROR(...);returnthis.concat(left,right.toString());}}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions