microsoft / microsoft/TypeScript

Add a "specify type" command to tsserver

Open
#43,291 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Suggestion

🔍 Search Terms

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

I would like to be able to highlight an expression/binding and have typescript let me input the type it should be instead of inferring the type and/or replacing the current type.

📃 Motivating Example

// a .js file, as I use JSDoc mostly
function double(a) {
  return a * 2;
}

I would like to be able to highlight a and have a JSDoc in JS or type position in TS open up for me to input the type number manually. In particular figuring out nesting for "casting" in JS can be confusing if applied to non-bindings:

let a = JSON.parse(_);

💻 Use Cases

I mostly want to use this for tooling that can integrate against existing code without my cursor jumping around to manually specify types. Having this be done and placing my cursor back where it was would be mildly convenient. Having it as an API would also let me do this automatically with some tooling that works on existing code instead of just code generators.

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

The request targets tsserver and describes a command that operates on a highlighted expression or binding. Start by tracing tsserver's existing commands for source edits and type information; done would mean accepting a manually entered type in JavaScript JSDoc or TypeScript type position, exposing it for tooling, and preserving the cursor location.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.