Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
myocytebd opened this issue Jan 3, 2025 · 0 comments
Assignees

Comments

@myocytebd
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants