Skip to content

Arithmetic operators don't work on type parameters #15523

Closed
@vkurchatkin

Description

@vkurchatkin

TypeScript Version: master

Code

function test<T extends number>(n: T) {
  var a = n * 1;
  var b = n - 1;
  var c = n + 1;
}

Expected behavior:

No errors

Actual behavior:

Following errors:

test.ts(4,11): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
test.ts(5,11): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
test.ts(6,11): error TS2365: Operator '+' cannot be applied to types 'T' and '1'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions