microsoft / microsoft/TypeScript

Show function return type inlay hints even for JS functions that have explicit type annotations

Open
#45,928 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: LS: Inlay Hints In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Suggestion

🔍 Search Terms

  • inlay hints
  • return type
  • function like
  • JavaScript

⭐ Suggestion

Currently the javascript.inlayHints.functionLikeReturnTypes.enabled setting in VS Code adds inlay hints to JS functions that do not have an explicit @return annotation:

// Shown here
function foo() /* : number */ { 
    return 1;
}

// But not here here
/** @return {number} */
function foo()  { 
    return 1;
}

This feels inconsistent, since I now have to look in different locations for the type information

I propose adding a new option that always enables these return types in JS files, even if there is an @return type annotation.

In the example above, this would result in the inlay hints showing on both functions:

function foo() /* : number */ { 
    return 1;
}

/** @return {number} */
function foo()  /* : number */ { 
    return 1;
}

This lets me read the code more like standard TypeScript

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 by tracing the existing javascript.inlayHints.functionLikeReturnTypes.enabled setting and how return types are suppressed when an @return annotation is present. Define the new option's interaction with that setting, then verify that both annotated and unannotated JavaScript functions show return-type inlay hints when enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.