microsoft / microsoft/TypeScript

Support `@var` or `@member` JSDoc tags

Open
#56,674 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: JSDoc Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

jsdoc
@var
@member

✅ Viability Checklist
⭐ Suggestion

Recognize and support JSDoc's @var or @member tags.

📃 Motivating Example

It will allow the declaration of globals in JS files that use JSDoc for checking that are not declared within that specific file.

This will then allow for tools and tool chains that add to the global scope for a file or program to be documented without using ts, d.ts or other ts exclusive notation and features.

💻 Use Cases
  1. What do you want to use this for?

Electron preload scripts and contextBridge.exposeInMainWorld!

  1. What workarounds are you using in the meantime?
/**@type {import("./preload.js").ElectronAPI} */
var ElectronAPI;
  1. What shortcomings exist with current approaches?

Relies on JS's support of variable redeclaration. Changing var to let throws the following error on runtime:

Identifier 'ElectronAPI' has already been declared

The following should do the same as the two lines above, but neither vscode nor TS supports it.

/** @var {import("./preload.js").ElectronAPI} ElectronAPI */

It does not rely on confusion inducing variable redeclaration and is much cleaner.

I believe it is also a way to declare members of a class without declaring them at the root level of the class.

These should be the same (as far as TS is concerned):

class test1{
    /**@type {string}*/
    name;
}

class test2{
    /**@var {string} name */
}

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 how TypeScript currently parses and applies JSDoc tags in JavaScript files. Compare the requested @var and @member examples with existing JSDoc behavior, including global declarations and class members. Done means the tags are recognized with the intended types without changing emitted JavaScript, with tests covering the motivating examples.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.