Skip to content

Find all refs/rename for mapped type symbols via Record #20272

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
OliverJAsh opened this issue Nov 26, 2017 · 5 comments
Closed

Find all refs/rename for mapped type symbols via Record #20272

OliverJAsh opened this issue Nov 26, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@OliverJAsh
Copy link
Contributor

TypeScript Version: 2.6.1.

Code

Renaming a should rename both instances of a T.a and O.a, but it doesn't.

{
  type T = { a: number, b: string };
  type O = Record<keyof T, {}>;
  var t: T = { a: 1, b: "s" };
  var o: O = { a: 3 };
}

If we replace Record with its underlying implementation, renaming does work:

{
  type T = { a: number, b: string };
  type O = { [key in keyof T]: {} };
  var t: T = { a: 1, b: "s" };
  var o: O = { a: 3 };
}

Related #12450

@mhegazy
Copy link
Contributor

mhegazy commented Nov 27, 2017

Duplicate of #11997

@mhegazy mhegazy marked this as a duplicate of #11997 Nov 27, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 27, 2017
@OliverJAsh
Copy link
Contributor Author

After reading that issue, I don't understand why this works when using mapped types and keyof directly, but not via the Record type alias which does exactly the same thing under the hood. 🤔

@OliverJAsh
Copy link
Contributor Author

To re-iterate:

// Renaming does work across mapped types
{
  type T = { a: number, b: string };
  type O = { [key in keyof T]: {} };
  var t: T = { a: 1, b: "s" };
  var o: O = { a: 3, b: 4 };
}
// Renaming does not work across mapped types
{
  type T = { a: number, b: string };
  type O = Record<keyof T, {}>;
  var t: T = { a: 1, b: "s" };
  var o: O = { a: 3, b: 4 };
}
// Renaming does not work across mapped types
{
  type T = { a: number, b: string };
  type MyRecord<T extends string, V> = { [key in T]: V }
  type O = MyRecord<keyof T, {}>;
  var t: T = { a: 1, b: "s" };
  var o: O = { a: 3, b: 4 };
}

@OliverJAsh
Copy link
Contributor Author

@mhegazy Hey! Do you have any ideas why this issue appears to only occur when using Record, but not when using mapped types and keyof directly? See my example in the comment above.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants