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

Rename string literal values #15370

Closed
maxime1992 opened this issue Apr 25, 2017 · 2 comments
Closed

Rename string literal values #15370

maxime1992 opened this issue Apr 25, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@maxime1992
Copy link

I have interfaces in my app.

Let's take a dog as example :

interface Dog {
  name: string
  id?: number
}

When I post a Dog on the server, I ask the user to give me the dog's name and the server will return an object of Dog type.

So my function to post the Dog only needs his name :

function postDog(name: string) {
   // ...
}

const dog: Dog = { name: 'wouaf' }
postDog(dog.name)

The thing is, if I decide to rename the Dog's name property, my function won't have the parameter renamed. (yes this is pure luxury 💎 and it wouldn't break anything in frontend at least because if my interface matches what the server is expecting ...)

So a collegue (@vnoel) helped me figure that out :

// utility
type Prop<T, K extends keyof T> = { [P in K]: T[P] }

type Doggy = Prop<Dog, 'name' | 'id'>

function f(o: Doggy) {
  console.log(o.id, o.name)
}

f({
  id: 5,
  name: 'wouaf'
})

This is great ! The only thing is that when I use F2 to rename the property (in VSC) :
image

Would it be possible to auto-rename the property everywhere ?
At least we have an error which is great for now :) But doing that automatically would be 🥇

PS : I think it's related to #7611 and #9257 but a little bit different

@mhegazy
Copy link
Contributor

mhegazy commented Apr 26, 2017

This is actually a duplicate of #13690. rename is built on top of find all refs.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 26, 2017
@ghost
Copy link

ghost commented May 8, 2017

This actually looks more like a duplicate of #11997.

@mhegazy mhegazy closed this as completed May 8, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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

2 participants