Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

"Insert type" quick fix #8

Closed
Dema opened this issue Apr 18, 2020 · 5 comments
Closed

"Insert type" quick fix #8

Dema opened this issue Apr 18, 2020 · 5 comments
Labels
✨ Feature New refactoring or feature 👋 Good first issue Good for newcomers

Comments

@Dema
Copy link

Dema commented Apr 18, 2020

Is this request related to a problem? Please describe.

Typescript can infer a lot of things and this helps with rapid development, but at some stage I usually like to put more types on my implicitly typed variables. And this kind of quick fix would be of a great help.

Describe the solution you'd like

Suppose we have implicitly typed variables especially in the form of destructuring.

const { a, b, c } = { a: 1, b: 2, c: "s" };

While cursor is inside const keyword there will be a quick fix "Insert type" that can add type like this

const { a, b, c }: { a: number; b: number; c: string } = { a: 1, b: 2, c: "s" };

This is the most complicated, but real world case. I'm trying to convert function with implicitly typed positional arguments into function that takes an object as an argument and this kind of quick fix would help me a lot.

Additional context

It would be great if this quick fix will be able to add types to any implicitly typed variable or function or object definition.

I think this could reuse some code from #3 feature request

@Dema Dema added the ✨ Feature New refactoring or feature label Apr 18, 2020
@nicoespeon
Copy link
Owner

That will be great indeed!

We need to sort out #3 before we can do that. My main blocker today is to get access to TS inferred type at the cursor position, from the extension 🤔

@Dema
Copy link
Author

Dema commented May 7, 2020

https://github.com/MartinJohns/vscode-inline-types/ Here is an extension that shows inferred types in code lens. But if I understand they just parse ts files by themselves.

@nicoespeon
Copy link
Owner

Yes, I went basically in the same direction using the typeChecker that's internal to TypeScript to implement one: https://github.com/nicoespeon/hocus-pocus/blob/master/src/create-function-with-types/type-checker.test.ts

For the moment it's also limited to the current file, but I guess that's a problem we'll be able to solve after.

We're working on implementing #3. From there, I guess this feature will be easier to build.

@nicoespeon
Copy link
Owner

IMO, this feature is ready to be implemented thanks to the TypeChecker. We have proved with #3 that we can infer types appropriately. There's everything we need to insert the inferred type 👍

I can provide some guidance for anyone who'd like to do it. Otherwise it will wait until we tackle it with @fabien0102 (we pair-prog every week to implement features, but we mostly focus on https://github.com/nicoespeon/abracadabra to be honest).

@nicoespeon nicoespeon added the 👋 Good first issue Good for newcomers label May 30, 2020
@nicoespeon
Copy link
Owner

Hey, thanks for reporting but it's been a while since I updated this extension and I'm not planning to do this in the foreseeable future. I'm archiving the extension 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ Feature New refactoring or feature 👋 Good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants