microsoft / microsoft/TypeScript

Extend JSDoc @this to JavaScript class - apply @this to every non-static method

Open
#62,041 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Let a node.js JavaScript (cjs) module:

// global .d.ts
declare class FooTS { tsProp: string; }
// xxx.js
// Goal: let intellisense treat class Foo's 'this' to fake class FooTS
// /** @this {FooTS} */ => currently this is invalid
class Foo {
    /** @this {FooTS} */
    constructor() { this.jsProp = 123; };
    /** @this {FooTS} */
    bar() { return this.tsProp; }
}

@this works for class methods, but it is verbose to add @this to every method.
It would be a QoL improvement to allow @this apply to JavaScript class with the effect that it apply @this to every non-static method.

This is probably invalid in original JSDoc, and doesn't make much sense.
But in vscode, it makes sense because user can use Typescript .d.ts for (more powerful and less verbose) type declaration for JavaScript implementation.

Alternatively, a more aggressive QoL could be that introduce a new tag to treat Foo type as FooTS type globally.

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 issue names no implementation file, test, or entry point. Start by locating TypeScript's existing JSDoc @this handling and the checks for JavaScript class methods, then review related tests. Done means a class-level @this can provide the this type for every non-static method without requiring repeated method annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
compilers, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.