Typescript: JavaScript Property Suggestions Do not Pick Up Type From JSDoc Comment

Created on 6 Jan 2017  路  4Comments  路  Source: microsoft/TypeScript

_From @mohsen1 on January 5, 2017 18:28_

  • VSCode Version: 1.8.1
  • OS Version: macOS

Steps to Reproduce:

  1. Make a file with following contents
var webpack = require('webpack')

/** @type {webpack.Configuration} */
var config = {
    module: {
        loa // expected autocomplete 
    }
}

module.exports = config;
  1. In line 6, based on webpak type definition I should autocomplete for loaders.

screen shot 2017-01-05 at 10 26 04 am

_Copied from original issue: Microsoft/vscode#18184_

Bug JavaScript VS Code Tracked

Most helpful comment

This appears to work as expected now using a standard JSDoc comment for the type of the config object. With the following code I get intellisense for its properties:

const webpack = require('webpack');

/** @type {webpack.Configuration} */
module.exports = {
  ...
};

Screenshot:

Using VS Code 1.45.1.

All 4 comments

Looks like a TS issue, unrelated to webpack and imports. Tested with 2.1.5 and 2.2.0-dev.20170106

Here's a simpler repo:

interface IFoo {
    bar: number
}

/** @type {IFoo} */
const foo = {

}

When typing inside of foo, we do not get a completion item for bar. If the code is changed to

interface IFoo {
    bar: number
}

const foo: IFoo = {

}

then bar is returned as a completion inside of foo.

Here's the TSServer communications in the bad case:

[Trace - 2:47:42 PM] Sending request: completions (1960). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "/Users/matb/projects/sand/bla.ts",
    "line": 7,
    "offset": 5
}
[Trace - 2:47:42 PM] Response received: completions (1960). Request took 1 ms. Success: false . Message: No content available.

Ran into similar problem, and just wanted to point out that I have imported types as follows. And this (workaround?) works pretty well in vscode v1.35.0-insider.

const HtmlWebpackPlugin = require('html-webpack-plugin');
const baseUrl = "/";

/** @type {() => import("webpack").Configuration} */
module.exports = () => ({
    plugins: [
        new HtmlWebpackPlugin({
            template: "index.ejs",
            metadata: { baseUrl }
        })
    ]
})

Yes the import("webpack").Configuration syntax works now.

This appears to work as expected now using a standard JSDoc comment for the type of the config object. With the following code I get intellisense for its properties:

const webpack = require('webpack');

/** @type {webpack.Configuration} */
module.exports = {
  ...
};

Screenshot:

Using VS Code 1.45.1.

Was this page helpful?
0 / 5 - 0 ratings