Skip to content

"Add explicit type" refactoring #865

@mikavilpas

Description

@mikavilpas

Is this request related to a problem? Please describe.

In short, this is to go from const foo = {...} to const foo: Thinginator<Thing | string> = {...}.

Pretty often I find myself seeing what type is inferred for my variables. The type inference usually works great, but here are some use cases where I like to type out the explicit type:

  • for clarity, an explicit type can help the reader understand better or more quickly
  • sometimes the type inference is misleading or it could be written in a clearer way

For functions it's already possible to add the return type with another refactoring.

Describe the solution you'd like

I would like to have a refactoring for this, such as "Add explicit type" or "Add type"

Additional context

Currently I do this by hovering the variable name with my mouse in order to bring up this popup (can also do it with with ⌘K ⌘I), and then selecting the contents with the mouse to copy them with ⌘C 😄

Here's a picture:

image

To be clear, here's what I would like to see after applying a refactoring for this:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ FeatureNew refactoring or feature🙅 Require better TypeCheckerThis refactoring would need Abracadabra to determine types faster and better than it can do

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions