簡體   English   中英

如何使vscode顯示來自另一個.js文件的導出函數的類型信息?

[英]How to make vscode show type info for exported function from another .js file?

通過/// <reference path ...注釋,可以很簡單地在vscode中顯示Typescript文件的類型信息。 但是,在某些情況下,我會使用另一個js文件中的導出函數。 導出的函數已注釋為包含類型信息。 這是一個示例(lib / index.js):

/**
 * Put the executing thread to sleep for the given amount of milliseconds.
 * @param {number} milliseconds
 */
exports.sleep = function (milliseconds) {
    var end = new Date().getTime() + milliseconds;
    while (new Date().getTime() < end) { }
}

在我的main.js文件中:

var lib = require("lib");
lib.sleep(500);

不幸的是,vscode不提供該sleep函數的調用簽名,我也不能使用cmd / ctrl + click導航到該函數。

我還創建了一個類型文件,並在main.js中引用了該文件,該文件的工作方式幾乎與我想要的一樣,只不過它不帶我到原始源,而是在我按cmd / ctrl +單擊該函數時進入類型文件。名稱。

是否可以以及如何讓vscode識別其他JS文件中的導出並為其提供調用信息和代碼導航?

require路徑更改為./lib

var lib = require("./lib");
lib.sleep(500);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM