jsconfig.json gives broken intellisense for js files with module.exports

未关闭
#33,435 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, typescript, vscode

调研方向

使用所示的 index.js、jsconfig.json、浏览器用法和 Node require 用法,在 VSCode 1.38.0 和 TypeScript 3.6.2 中复现该行为。比较直接的 module.exports 与替代别名的 IntelliSense,并在 jsconfig.json 和 require 都能一致地提供该库及其属性时,认为该 issue 已完成。

由索引模型根据 Issue 内容生成。

描述

Awaiting More Feedback Suggestion
  • VSCode Version: 1.38.0
  • TS Version: 3.6.2
  • OS Version: Ubuntu 18.04 LTS bionic beaver
  • Tested with no extensions
  • Can not really find a solution to this problem after a lot of searching

I have a personal js library that I use both in browser-side and node-side for a lot of my personal projects . In fact the library itself has its own project . The js library looks like this :

const library = {};

library.foo = function() {/*browser code*/}

if (typeof module === 'object') {
 library.bar = function() {/*node code*/}
 module.exports = library;
}

For a browser project (library is used via script tag) If I try to get intellisense via jscofig.json for such a file I get broken intellisense (by typing f or b I get suggestions for foo or bar respectively , but there is no library suggestion when I type l , and even if I type library I get no suggestion about its properties ) .
For a node project everything works fine regarding intellisense using require .

The issue here is with module.exports . If I change it to var substitute = module; substitute.exports = library; then I get intellisense for browser project via jsconfig.json but broken intellisense (as described before) for node via require .

How can I get intellisense to work for both require and jsconfig.json ?

Before you attempt to check intellisense you should know the following :

I open index.js in a project that does not have any other js file and no jsconfig.json file . Then I view in the same VScode session some other , completely unrelated to my project , js files . For whatever file I view I get intellisense (of the globally scoped variables that have been defined via let , var or const) when I am editing index.js . If the unrelated js file happens to have module.exports then the intellisense that I get in index.js for that file is broken like it has been described before .
I stop getting intellisense for files that I view when I create a jsconfig.json file file in the folder of index.js . But still there is the same broken behavior with intellisense for files that are included via jsconfig.json and have module.exports .

Please restart vscode to test if intellisense really works .

主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。