![](/img/trans.png)
[英]Intellisense not working with imports in Visual Studio Code
[英]Get Visual Studio Code to give intellisense for custom Javascript imports
我正在使用TestComplete編寫自動化測試腳本。 TestComplete主要支持Ecmascript 2015,但是它有一些古怪之處,導致智能感知無法正常工作。
這是代碼文件的兩個示例:
文件: 有用的StuffFileName.js
class UsefulStuff {
constructor(initValue) {
this.initValue = initValue;
}
get someValue(){
return this.initValue + " someValue";
}
doStuff(input) {
return input + " stuff done";
}
}
module.exports.UsefullStuff = UsefullStuff;
文件: WorkingHere.js
var useful = require('UsefulStuffFileName');
class WorkingHere {
constructor() {
this.usefullStuff = new useful.UsefulStuff("Hello");
}
doCoolStuff() {
// I want intellisense options when I type the period after this.usefulStuff
// The options would be someValue, doStuff() and initValue.
// |
// |
// V
let myVariable = this.usefullStuff.someValue;
}
}
我認為這些怪癖是:
module.exports.UsefullStuff = UsefullStuff;
。 (這使其可以與TestComplete一起使用。) var useful = require('UsefulStuffFileName');
) new useful.UsefulStuff("Hello");
)。 無論如何,有沒有配置Visual Studio Code來了解這些文件之間的關系並給我帶來智能?
注意:如果我嘗試import {UsefulStuff} from './UsefulStuffFileName';
更標准的import {UsefulStuff} from './UsefulStuffFileName';
我從TestComplete收到一條錯誤消息,提示“意外的令牌導入”。
可以通過以下步驟完成。
將導入更改為如下所示:
var { UsefulStuff } = require('UsefulStuff');
將類的實例更改為如下所示:
this.usefulStuff = new UsefulStuff("Hello");
添加一個名為jsconfig.json
的文件,並將其放入其中:
。
{
"compilerOptions": {
"baseUrl": "."
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.