Skip to content

Find all refs/rename for mapped type symbols #12450

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
mhegazy opened this issue Nov 22, 2016 · 4 comments
Closed

Find all refs/rename for mapped type symbols #12450

mhegazy opened this issue Nov 22, 2016 · 4 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Nov 22, 2016

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

renaming a should rename both instances of a T.a and O.a.

@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 22, 2016
@mhegazy mhegazy added this to the TypeScript 2.2 milestone Nov 22, 2016
@mhegazy mhegazy assigned ghost Nov 22, 2016
@ghost ghost closed this as completed in #13658 Jan 24, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 24, 2017
@pavel-agarkov
Copy link

Hello.
Rename does not work when you map namespaces or objects imported from another module .
For example:

namespace Core {
    export class Class1 { static order: "1" }
    export class Class2 { static order: "2" }
}

type CoreTypes = keyof typeof Core;
type CoreObject = {[P in CoreTypes]: typeof Core[P]["order"]};
const core: CoreObject = {
    Class1: "1",
    Class2: "2"
}

I don't even talk about order property. The main problem is that class name rename does not rename property of CoreObject.
Everything works the same way when I use imports instead of namespaces:

import * as Core from "./file-with-exported-classes"

IDE: VSCode 1.15.1 / VS2017 15.3.3
TypeScript: 2.5.2
Node: 6.11.0

Would it be considered as a bug/improvement request?
Thank you.

@ghost
Copy link

ghost commented Sep 6, 2017

Hi @pavel-agarkov, your example works if you remove the CoreTypes type alias and write type CoreObject = {[P in keyof typeof Core]: typeof Core[P]["order"]}; directly.
A simpler example:

interface X { x: number };
type Key = keyof X;
const a: { [P in Key]: string } = { x: "" }; // Can't find reference for `x`
const b: { [P in keyof X]: string } = { x: "" }; // Successfully find reference for `x`

I'm not sure if this is a bug or a limitation of the way we do mapped types. CC @sandersn

@pavel-agarkov
Copy link

Thank you, @Andy-MS
It works as you said.
It a little bit less handy since even my example is way more simplified compared to the real world...
But I can live with it :)

@OliverJAsh
Copy link
Contributor

For some reason this doesn't work when the Record type alias is used:

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

I filed a separate issue #20272

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants