Skip to content

TS2536 when deep remapping #52896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
klarezz opened this issue Feb 21, 2023 · 3 comments
Closed

TS2536 when deep remapping #52896

klarezz opened this issue Feb 21, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@klarezz
Copy link

klarezz commented Feb 21, 2023

Bug Report

πŸ”Ž Search Terms

TS2536: Type cannot be used to index

πŸ•— Version & Regression Information

v4.9.5

⏯ Playground Link

Playground Link

πŸ’» Code

type Obj = {
  a: {
    b: {
      c: unknown
    }
  }
};

type ReMap = {
  [P in keyof Obj]: {
    [M in keyof Obj[P]]: Obj[P][M]["c"]
  }
};

πŸ™ Actual behavior

Code below throws TS2536: Type "c" cannot be used to index type 'Obj[P][M]'

πŸ™‚ Expected behavior

No error?

Related?

Could be related to #21760

@klarezz
Copy link
Author

klarezz commented Feb 21, 2023

@MartinJohns, I updated the issue, could you please explain what I'm doing wrong?

@RyanCavanaugh
Copy link
Member

I think this is just a duplicate of the one you linked.

Anyway this code is equivalent and works well:

type Obj = {
  a: {
    b: {
      c: string
    }
  }
};

type GetC<T> = T extends { c: infer O } ? O : never;

type ReMap = {
  [P in keyof Obj]: {
    [M in keyof Obj[P]]: GetC<Obj[P][M]>;
  }
};

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 21, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants