-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
String Literal refactoring support #5602
Comments
+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. |
This will require a breaking change in the type checker API because right now the exposed |
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 |
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. |
Thanks for #5185 🌹. Would be great if we could get refactoring support for string literals
refs #5554 (comment)
The text was updated successfully, but these errors were encountered: