microsoft / microsoft/TypeScript

In a JS file, using module.exports in a file changes the type of module from NodeModule to typeof import("...")

Đang mở
#43,363 3 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ả

Bug Report

When using a JS file with @types/node, the type of module changes from NodeModule to something strange (typeof import("/sandbox/not_working");) after including a line like module.exports = {}.

🔎 Search Terms

module.exports, NodeModule, typeof import

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 4.2.3
⏯ Playground Link

CodeSandbox link with relevant code

💻 Code
/// <reference types="node"/>
// INFO: This is JS

/**
 * @param {NodeModule} aModule
 */
function createLogger(aModule) {}

createLogger(module); // INFO: module here is triggering the error.

// INFO: THIS LINE BREAKS IT
module.exports = {};

🙁 Actual behavior
var module: {
    "\"/sandbox/not_working\"": typeof import("/sandbox/not_working");
}

Argument of type '{ "\"/sandbox/not_working\"": typeof import("/sandbox/not_working"); }'
is not assignable to parameter of type 'NodeModule'.

  Type '{ "\"/sandbox/not_working\"": typeof import("/sandbox/not_working"); }'
  is missing the following properties from type 'NodeModule': require, id, filename, loaded, and 3 more.

ts(2345)
🙂 Expected behavior

I expected module to always be of type NodeModule.

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

Bắt đầu với ví dụ CodeSandbox và bản tái hiện trong not_working.js, tập trung vào cách module.exports = {} thay đổi kiểu được suy luận của module. Xác nhận hành vi dự kiến của NodeModule và thêm một bài kiểm thử hồi quy cho thấy createLogger(module) vẫn hợp lệ sau phép gán export.

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
Lĩnh vực
compilers
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
35/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.