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

Extract Interface to file #488

Open
kevintechie opened this issue Jan 14, 2022 · 2 comments
Open

Extract Interface to file #488

kevintechie opened this issue Jan 14, 2022 · 2 comments
Labels
💪 Improvement Refactoring doesn't run on a specific case or result could be optimized

Comments

@kevintechie
Copy link

Describe what's missing

Add a command to extract a class interface to file.

How would it work

The command would take the output from the existing Extract Interface command and rather than placing the extraction at the bottom of the current file, it would create a new file and place the extracted interface there.

Expected behavior

The name of the extraction file should follow general interface filename convention: IClassName.ts
The name of the extracted interface should follow the same convention: IClassName
The interface declaration should be prefixed with the export keyword: export interface IClassName {...}
Any dependent imports should be added to the top of the file before the export interface
An error notification should display if a file of the same name already exists: "Interface file already exists."

@kevintechie kevintechie added the 💪 Improvement Refactoring doesn't run on a specific case or result could be optimized label Jan 14, 2022
@nicoespeon
Copy link
Owner

nicoespeon commented Jan 14, 2022

Oh, that's an interesting idea!

I think I'd tweak a little bit the expected behavior so we ask the user which name they want to give their interface. We may provide a default input, but that will make it easier to change rather than having to rename the created file if you have a different convention (e.g. personally, I tend to avoid I in the interface name, but that's a personal convention and it's not a popular one).

The rest is very doable. We can check the existence of such file, create it if it doesn't exist, move the declaration here and eventually import whatever dependency needs to be (types, mostly).

🤔 Thinking about how to "improve" the existing behavior, I guess we could prompt the user to ask whether they want to extract the interface in the same file or another. Default would be the existing behavior (same file), but you can quickly pick "new file" and then be prompted with the interface name. That should keep the UX smooth.

@kevintechie
Copy link
Author

All good ideas. The only reason I suggested a separate command option is to streamline the process for my typical workflow. However, even if a user had to choose an option for file, it's faster than the manual work I have to do with the current behavior. (Which is WAY better than other automated tools I've tried and infinitely better than doing it manually.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 Improvement Refactoring doesn't run on a specific case or result could be optimized
Projects
None yet
Development

No branches or pull requests

2 participants