You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rename and fine all references of Typescript's string literal values #7611
//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.
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>;
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
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.:
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.
Activity
mhegazy commentedon Apr 29, 2016
so should we rename all literal types
"option 1"or just the ones from this declaration?for example:
Fix #7611: Add support for String Literal Types in find all refs and …
Fix #7611: Add support for String Literal Types in find all refs and …
Merge pull request #8366 from Microsoft/Fix7611-2
zivni commentedon 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:
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 to
getElementsByTagName(tagname: "renamed_article"): NodeListOf<HTMLElement>;And also the find all references does not work
Tried it on vscode 1.7.1 on windows.
mhegazy commentedon Nov 18, 2016
there is really no difference between
"aaa"intype Aand intype B. they are really the same type. the lib.d.ts change should be disabled, this is tracked by #7458zivni commentedon 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.:
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.