Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsDoc - set type without importing file

I'm using Angular 1 in VScode. I have a main file that defines all my services, controllers etc and require's them against Angular.

angular.module('myApp', [])
    .service('myService', require('./myService.js')
    .controller('myController', require('./myController.js');

and the service:

class MyService {
    constructor() {}
}

module.exports = MyService;

and my controller

class MyController {
    constructor(myService) {    
        /** @type {MyService} */
        this.myService = myService;
    }
}

module.exports = MyController;

As a result intellisense has no idea what myService is within the controller. I had hoped that the jsDoc comment would have solved this issue as both files are within the same work-space but it does not.

I have seen the type-def comment and tried writing a custom type in the service file :/** {MyService} CustomService */ then reference the CustomService type in my controller but that doesn't work either.

In Short Is it possible, using jsDoc in VSCode to reference a class from a different file without requiring it into the current working file.

Thanks for any insight all.

like image 824
ste2425 Avatar asked May 09 '26 07:05

ste2425


1 Answers

No, as of VScode 1.14 this is not possible but we are tracking a discussion of this functionality here: https://github.com/Microsoft/TypeScript/issues/14377

like image 87
Matt Bierner Avatar answered May 10 '26 21:05

Matt Bierner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!