Skip to content
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

Unable to rename the property of destructuring assignment #6312

Closed
falsandtru opened this issue Jan 1, 2016 · 6 comments
Closed

Unable to rename the property of destructuring assignment #6312

falsandtru opened this issue Jan 1, 2016 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@falsandtru
Copy link
Contributor

Rename a to b.

function f({a}: {a}) {
    f({a});
}

expected:

function f({b}: {b}) {
    f({b});
}

actual:

// rename the variable
function f({b}: {a}) {
    f({b});
}
// rename the declaration
function f({a}: {b}) {
    f({b});
}
@falsandtru falsandtru changed the title Unable rename the property of destructuring assignment Unable to rename the property of destructuring assignment Jan 1, 2016
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 1, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Jan 7, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Jan 13, 2016

Please check the repro in #6459 (comment) as well.

@falsandtru
Copy link
Contributor Author

I was able to reproduce that problem.

// renamed `A#foo` to `A#bar`
class A {
  bar: string;
}

class B {
  syntax1(a: A): void {
    let { foo } = a; // error, should be `{ bar }`
  }
  syntax2(a: A): void {
    let { bar: foo } = a;
  }
}

@RyanCavanaugh
Copy link
Member

Another repro courtesy of @falsandtru that we should add tests for:

Code

Rename var a to var c in a.ts.

// a.ts
export var a;
// b.ts
import {a} from './a';
export {a}

Expected behavior:

import {c} from './a';
export {c}

Actual behavior:

import {c} from './a';
export {a}

sheetalkamat added a commit that referenced this issue Apr 5, 2016
sheetalkamat added a commit that referenced this issue Apr 6, 2016
@sheetalkamat
Copy link
Member

Another repro from test cases found during fixing this about destructuring assignment:

interface I {
    property1: number;
    property2: string;
}
var elems: I[];

var p2;
for ({ /*This should be referenced too*/property1 : p2 } of elems) {
}

@ghost
Copy link

ghost commented Feb 10, 2017

This still does not work reliably. For example:

const x = 1;
const o = { x };
{
    const { x } = o;
    x;
}

Renaming any x will result in broken code.

@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2017

leaving this issue and using #15787 to track the change.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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

5 participants