-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
module not resolved in JS file using var x = require('...')
syntax
#11825
Comments
@timty thank you for opening this issue. I have confirmed this with the latest bits and no extensions. Migrating to JavaScript language service. Code to copy and paste. class Foo {
bar() {}
}
var f = new Foo();
// IntelliSense works correctly
// f.
/**
* @param {Foo} x
*/
function zoo(x) {
// IntelliSense is not being given
x.
} |
@waderyan your code doesn't repro for me on master. Intellisense works fine when I paste the code in a javascript file. Intellisense does not work for me in a TypeScript file, but Typescript doesn't rely on jsdoc to give types to parameters. It only uses the documentation.
@timty Are you using typescript or javascript? In a typescript file you will not get intellisense for the above reason. In a javascript file the code you gave will not work either, because jsdoc requires the parameter name to match: /**
* @param {Pool} pool2 <-- Names must match
*/
function myFunction(pool2) {
pool2./*intellisense should work now*/
} If you're using typescript, then you have to use the postfix type syntax: |
Thank you both for your responses. I am using javascript (nodejs). Sorry about the typo when recreating the issue. This does not work with correctly matching names either.
Intellisense here: No Intellisense with JSDoc type: No Intellisense with JSDoc param: |
The Pool type was not imported in the module, it is visible as pg.Pool |
@alexrock nice catch.
@sandersn really glad things are staying that way. jsdoc comments are often out of sync with the actual code. Also they are quite ugly. I have a colleague who uses JetBrain's Webstorm and it auto emits all these meaningless jsdoc tags into a pure typescript project... sorry for the rant. |
@alexrock @aluanhaddad |
@timty you imported the module with the binding import pg = require('pg');
/**
* @type {pg.Pool}
*/
var pool1; B import pg = require('pg');
import { Pool } from 'pg';
/**
* @type {Pool}
*/
var pool1; |
@aluanhaddad Thanks for the feedback. Got it working with Option B...
However for the sake of completeness this does not seem to work...
|
I don't think that the language service has special knowledge of the It does understand ES module syntax and the typescript-only @timty it's good that you can use ES module syntax to work around this. Does Option B need both lines to work? I'll leave this bug open until we decide whether the language service should also support |
var x = require('...')
syntax
@andy-ms poked around the code and there is code that looks for |
@sandersn @andy-ms Your suspicions are correct. No intellisense with the require pattern at least in this case. No Intellisense here:
Intellisense works here:
|
The issue here is that there is no in the case of the ES6 import, there is a type called if we want to make this to work, we need to make sure that |
Yes! In TS 2.3, var pg = require('pg');
/** @type {pg.Pool} */
var pool1; It should work for intellisense and checkJs. #14377 is another solution for this issue. |
@vladima you wrote the code for |
I do not think we should treat values as types or namespaces; this will just lead to confusion in the future. #14377 would be the way we would proceed with this request. |
Seems like another variant of #16489 |
From @timty on October 19, 2016 17:18
Intellisense works great for my postgress Pool type when explicitly declared:
However when passed as a parameter to a function and described through a JSDoc parameter intellisense fails:
Copied from original issue: microsoft/vscode#14008
The text was updated successfully, but these errors were encountered: