(See Screenshot)
I have this function with a really long untyped object returned, I want to copy the inferred type of that object because it's way too long to do manually, and then I want to make class/interface of it, example:
export class PatientTables {
emsf: string;
cadNumber: string;
// and so on
}
is there a way to copy it from somewhere as it seems Visual Studio Code already has it assorted somewhere, as you can see in the picture (48 more), how can I make it show the rest and copy it? thanks!
Code Actions = Quick Fixes and refactorings#Clicking on the Code Action lightbulb or using the Quick Fix command Ctrl+. will display Quick Fixes and refactorings. If you'd just like to see refactorings without Quick Fixes, you can use the Refactor command (Ctrl+Shift+R).
Rename All Occurrences If you select a variable/method and hit F2, you can edit the name and it will change every instance of that variable's name throughout the entire current working project.
You can get the type from the following code:
function createPatientTables() {
return {
foo: 'hello world',
bar: 123
};
}
type PatientTables = ReturnType<typeof createPatientTables>;
One approach is to use the tsc
command line tool. If you can isolate the file so that there are no dependencies, then you can run:
tsc filename.ts --declaration --emitDeclarationOnly
The resulting filename.d.ts
file will include the generated type.
Right click the function name, choose "refactor", then "Infer function return type".
This doesn't directly answer your question, but I think it solves your problem. The extension takes JSON and converts it into TypeScript interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With