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 and fine all references of Typescript's string literal values #7611

Closed
dbaeumer opened this issue Mar 21, 2016 · 4 comments
Closed

Rename and fine all references of Typescript's string literal values #7611

dbaeumer opened this issue Mar 21, 2016 · 4 comments
Assignees
Labels
Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@dbaeumer
Copy link
Member

From @zivni on March 20, 2016 8:40

Type script string literals allow to have a code such as

//interfaces.d.ts
type Options = "option 1 " | "option 2" 

//file.ts
let myOption: Options = "option 1" // "option 3" will give us an error, right in the IDE.

It would be nice to be able to rename and find all references of a specific value. e.g. find/rename all occurrences of "option 1". Currently we can only find the references of the type itself.

Copied from original issue: microsoft/vscode#4469

@dbaeumer dbaeumer self-assigned this Mar 21, 2016
@DanielRosenwasser DanielRosenwasser added Visual Studio Integration with Visual Studio Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined labels Mar 21, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Apr 29, 2016

so should we rename all literal types "option 1" or just the ones from this declaration?

for example:

type Options = "option 1" | "option 2"
let myOption: Options = "option 1" // rename here,

function foo(a: "option 1") { } // should this be renamed as well?

@mhegazy mhegazy added Suggestion An idea for TypeScript and removed Visual Studio Integration with Visual Studio labels Apr 29, 2016
@mhegazy mhegazy self-assigned this Apr 29, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 1, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone May 1, 2016
mhegazy added a commit that referenced this issue May 2, 2016
Fix #7611: Add support for String Literal Types in find all refs and occurances
@zivni
Copy link

zivni commented Nov 17, 2016

This does not work as accepted. I don't know if this problem is with Typescript or with VSCode.

Just open a new test.ts file with this content in vscode:

type A= "aaa" | "article" 
type B = "aaa" | "ccc"

var a:A="aaa"
var b:B="aaa"

press F2 to rename the "aaa" of the A type. the "aaa" of the B type is also renamed.
It goes even further, rename the "article" of the A type. You'll notice that it changed the typing in lib.es6.d.ts togetElementsByTagName(tagname: "renamed_article"): NodeListOf<HTMLElement>;

And also the find all references does not work

Tried it on vscode 1.7.1 on windows.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 18, 2016

there is really no difference between "aaa" in type A and in type B. they are really the same type. the lib.d.ts change should be disabled, this is tracked by #7458

@zivni
Copy link

zivni commented Nov 18, 2016

I will have to disagree.
It like saying that 2 properties with the same name in two different interfaces are the same.

Lets take a more concrete example: As typescript doesn't yet have a nameof operator, a common practice, when you need to pass a member name to a function, is to list members using a string literal types. E.g.:

type UserMembers = "id" | "name | ...
interface User{
   id: string
   name: string
   //...other properties
}

type OrderMembers = "id" | "name | ...
interface Order{
   id: string
   name: string
   //...other properties
}

// and then:
const orderByFields:UserMemebers[] = ["name","id"]
let orderedUsers=_.orderBy(users,orderByFields)

No lets say we decide to rename the members to more meaningful names, like userId and orderId, or userName and orderName. The interfaces will be renamed as accepted, but the string literal types will not.

Another example could be tat each have a status member with there own string literal types. and you need to change just a status name og just one of them

Also the problem described in #7458 is a different problem. there the rename is of a specific member, and what was wanted is to rename a specific instance of "html" code. Here the problem with article is that it renames something that is entirely unconnected to the renamed object.

@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
Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants