Skip to content

Mapped type loses type bound when used with arithmetic operator #15501

Closed
@ghost

Description

TypeScript Version: nightly (2.4.0-dev.20170501)

Code

interface I { x: number; }

type IdentityMap<T> = {
    [P in keyof T]: T[P];
};

function f<T extends I>(i: IdentityMap<T>) {
    const n: number = i.x; // No error, good
    i.x * 2; // Error
}

Expected behavior:

No error.

Actual behavior:

src/a.ts(9,5): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

May be related to #14360.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions