-
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
Suggestion: Refactor extract to type alias/typedef #23869
Comments
it's very helpful to me |
@Kingwl is that something you would be interested to implement as well? we would accept a PR for this one. |
sure,but it going to be late,my deadline is coming😂 |
something need to consider:
|
I think you are confusing this feature with extract to named arguments. e.g. |
Yes, I confused the two feature (:sad) , this one looks like this is a relatively simple operation |
could you give some advice about the new name of the newType? |
dose not matter what name you pick really. it has to be unique. The new name will be the rename location for the refactoring, and thus the user will get to update it immateriality after the refactor is applied. |
should it trigger with signal primitive type and extract to a type alias? |
I suppose so.. any type node really should be extractable.. |
@Kingwl we were just wishing we had this 😉 |
I'll on it😂 |
The 3.4 release notes mention this issue for providing feedback about this feature were they to expand it to create a type for the new parameter object. I feel like a nice convention would to be to tap into the name of the function and its class if the function is a method to arrive at the following convention: Example: Before refactor: class Foo {
bar(a: string, b: number) {
console.log('bar');
}
} Refactored: interface FooBarOptions {
a: string;
b: number;
}
class Foo {
bar(o: FooBarOptions) {
console.log('bar');
}
} Instead of The parameters interface would be placed in the same file because it would make sense for another module to import this module in order to reference its types and use its functions. The developer could move the interface into another file if they wanted to. |
Thanks @Kingwl! |
TypeScript Version: 2.9.0-dev.201xxxxx
Search Terms: Refactor, extract type, typedef
In a TypeScript file
Extract to type alias
:would generate:
In a JavaScript file
Extract to typedef
:would generate:
gif courtesy of @DanielRosenwasser
The text was updated successfully, but these errors were encountered: