Skip to content

Operator '+' cannot be applied to types 'T' and 'T'. #12410

Closed
@Jameskmonger

Description

@Jameskmonger

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

function add<T extends string | number>(x: T, y: T): T {
  return x + y;
}

add<string>("a", "b");
add<number>(5, 3);
add("a", "b");
add(5, 3);

Expected behavior:

Code to compile fine, because T is of type string | number and therefore can have the + operator applied.

Actual behavior:

Operator '+' cannot be applied to types 'T' and 'T'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA 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