microsoft / microsoft/TypeScript

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

Đang mở
#33,435 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

  • 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 .

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện hành vi trong VSCode 1.38.0 với TypeScript 3.6.2 bằng cách sử dụng index.js được cung cấp, jsconfig.json, cách sử dụng trong trình duyệt và cách sử dụng Node require. So sánh IntelliSense đối với module.exports trực tiếp với alias thay thế, và coi issue là hoàn tất khi cả jsconfig.json lẫn require đều cung cấp thư viện và các thuộc tính của nó một cách nhất quán.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript, vscode
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.