Skip to content

Two equally defined mapped types are incompatible #14613

Closed
@jtheisen

Description

@jtheisen

TypeScript Version: 2.1.5

Code

class A<T> { a: T }
type M<T> = {[P in keyof T]: A<T[P]>}

function foo<T>(m: (t: T) => M<T>, t: T) {
    let x: {[P in keyof T]: A<T[P]> } = m(t);
}

Expected behavior:

Should compile.

Actual behavior:

Fails to compile at the initialization of x with the claim the types were incompatible:

app.ts(200,9): error TS2322: Type 'M<T>' is not assignable to type '{ [P in keyof T]: A<T[P]>; }'.
  Type 'A<T[P]>' is not assignable to type 'A<T[P]>'. Two different types with this name exist, but they are unrelated.

    Type 'T[P]' is not assignable to type 'T[P]'. Two different types with this name exist, but they are unrelated.

(Maybe this is the expected behavior for some reason, but it seems off to me.)

Activity

ahejlsberg

ahejlsberg commented on Mar 12, 2017

@ahejlsberg
Member

Duplicated of #12832. Already fixed in #13448.

added
DuplicateAn existing issue was already created
FixedA PR has been merged for this issue
on Mar 12, 2017
locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jtheisen@ahejlsberg@mhegazy

        Issue actions

          Two equally defined mapped types are incompatible · Issue #14613 · microsoft/TypeScript