microsoft / microsoft/TypeScript

Add refactoring action to annotate a variable or a function signature component with its inferred type

Open
#13,199 15 comments 20 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: LS: Refactorings Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Hi, I'm using latest stable VSCode / latest nightly TS and I'm not sure if codefixes and refactorings have been implemented there yet, in any case, having a refactoring option to take any variable which receives an implicit inferred type, say, through a function call:

function test(): number[] {
  // ...
}

let x = test(); 

And being able to right-click x and invoke an action like Annotate with inferred type (or Extract inferred type), such that the resulting statement would look like:

let x: number[] = test();

could be very useful!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript codefix and refactoring behavior used by VSCode, reproducing the example with the latest nightly TypeScript. Define how the action should handle inferred variable types and function-signature components, then verify that it produces annotations such as let x: number[] = test();.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.