Skip to content

JsDoc @this Doesn't work for callback function #23474

@mjbvz

Description

@mjbvz

From @Cow258 on April 17, 2018 3:21

I am doing a class library and some function like jQuery.each().

I am trying to define [this] in callback function.

But it doesn't work...

Input code

/** 
 * @this {Car} 
 * @type {function(Car):boolean} 
 */
var callback_tips = function () { }
var Cars = [];
class Car {
    constructor(name) { this.name = name; this.x = 0; }
    Forward(step) { this.x += step; }
    
    /** @param {callback_tips} callback */
    static Each(callback) {
        for (let car of Cars) { callback.apply(car, car); }
    }
}
(function main() {
    Cars = [new Car('A'), new Car('B'), new Car('C')];
    console.log(Cars);
    // <!-- BUG HERE
    Car.Each(function (car) { this.name += this.name; this.Forward(5); }); 
    // BUG HERE -->
    console.log(Cars);
})();

Debug output

[ Car { name: 'A', x: 0 }, Car { name: 'B', x: 0 }, Car { name: 'C', x: 0 } ]
[ Car { name: 'AA', x: 5 }, Car { name: 'BB', x: 5 }, Car { name: 'CC', x: 5 } ]

JSDoc configuration

Default VSCode configuration

Expected behavior

Showing up tips about Car class when typing [this].
vscode2

Current behavior

Bug? callback -> this -> *:any .

Normal callback tips is working .
vscode1 .
But [this] do not work .
vscode2

My environment

Software Version
VSCode 1.22 (March 2018)
JSDoc ???
Node.js 9.10.1
npm 5.6.0
Operating system MacOS 10.12.6

Copied from original issue: microsoft/vscode#48021

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions