Thanks for https://github.com/Microsoft/TypeScript/pull/5185 :rose:. Would be great if we could get refactoring support for string literals
type Foo = "aReallyLong" | "bReallyLong"; // allow me to rename any of these values
let foo:Foo;
foo = "aReallyLong"; // allow me to rename this value
refs https://github.com/Microsoft/TypeScript/issues/5554#issuecomment-155622379
+1
PRs are welcomed.
The change should be done in services.ts::getReferencedSymbolsForNode. String literals do not have a symbol, so we will need to check their contextual type, and if it is a string literal type, replace all strings with the same contextual type.
so we will need to check their contextual type
This will require a breaking change in the type checker API because right now the exposed getContextualType returns the apparent type.
ah. we can add another one, to return the string literal type at a location then.
I think we should just do the correct thing and make the break. I don't think most people will be affected by it, and It's going to be necessary elsewhere. We should favor a more general solution that gets users where they need to be than one that solves a specific use-case. I'll make the change and see what breaks in our language service.
another case:
interface TestA {
'propA': number;
}
type TestAKey = keyof TestA;
function FnA<K extends TestAKey>(type: K, val: TestA[K]) {}
FnA('propA', 0);
Support for renaming refactoring will be useful for functions like addEventListener.
Bump. Perhaps this wasn't that urgent in 2015 when filed, but now with the level of sophistication TS has reached I think this should be reconsidered for roadmap.
Whether this feature exists or not is a pretty big deal wrt. what should be considered best practice for enums when writing new code/new APIs.
String literals have benefits over enums as they require no imports to be used, is easy to debug and serialize, and makes for less verbose code. Also a critical tool for javascript interop where there are no pre-existing enum objects.
Without refactoring support, committing to string literals as best practice for how we design APIs in TypeScript is sketchy.
I don't get something...It looks like Intellij IDE can do exactly what we ask for in this Issue. How the hell Intellij can do this if it's not supported in Typescript itself?
Maybe IntelliJ implements their own language service?
I don't know...Maybe typescript already supports this and it's now an issue with VScode? What about this merged commit #5615, did it solve the issue?
That would be very handy to have such feature in TypeScript
Bump. This should be a feature in TypeScript and VSCode in 2020. Right now to get refactoring behavior in VSCode you have no choice but to use string enums, which are far less elegant
mega bump
I'd like to take a try on this.
Most helpful comment
I'd like to take a try on this.