Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "extract interface from a class" in TypeScript using VSCode?

For example, in C# and Visual Studio, you can right click on class, and click on an option to extract an interface from a class, which will basically auto-generate all the public methods/properties signatures as an interface. This feature is a pretty handy refactoring when you're trying to make code unit-testable.

Is there a way to do the above using TypeScript and VSCode? It doesn't look like this feature is supported out of the box.

like image 308
burnt1ce Avatar asked Jan 23 '26 03:01

burnt1ce


1 Answers

Afaik there is no such thing: https://code.visualstudio.com/docs/typescript/typescript-refactoring

But you could create an extension that parses AST and runs through public functions and creates an interface.

like image 173
iMike Avatar answered Jan 24 '26 20:01

iMike