microsoft / microsoft/TypeScript

Ability for checker to resolve modules by node similar to program when providing custom host

Đang mở
#61,941 7 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.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

🔍 Search Terms

module resolution location

✅ Viability Checklist
⭐ Suggestion

The program provides the ability to resolve modules based on the specific string literal node, but the checker only resolves based on specifier text and node resolution mode. This means that if module specifiers with the same text and resolution mode resolve to different modules, the checker will always resolve to the same module based on whatever was last inserted into the program's ModeAwareCache.

https://github.com/microsoft/TypeScript/blob/47ca599979c418ade9b0a2f4107c305822472e44/src/compiler/program.ts#L1973-L1975

📃 Motivating Example
import text from "./data.txt" with { type: "text" };
import bytes from "./data.txt" with { type: "bytes" };
const { default: textDynamic }   = await import("./data.txt", { with: { type: "text" }});
const { default: bytesDynamic } = await import("./data.txt", { with: { type: "bytes" }});

let invalid: number;
invalid = text;
invalid = textDynamic;
invalid = bytes;
invalid = bytesDynamic;

let validText: string;
validText = text;
validText = textDynamic;

let validBytes: Uint8Array<ArrayBuffer>;
validBytes = bytes;
validBytes = bytesDynamic;

Currently outputs:

[ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = text;
~~~~~~~
    at file:///V:/scratch/main.ts:7:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = textDynamic;
~~~~~~~
    at file:///V:/scratch/main.ts:8:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = bytes;
~~~~~~~
    at file:///V:/scratch/main.ts:9:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = bytesDynamic;
~~~~~~~
    at file:///V:/scratch/main.ts:10:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'string'.
validText = text;
~~~~~~~~~
    at file:///V:/scratch/main.ts:13:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'string'.
validText = textDynamic;
~~~~~~~~~
    at file:///V:/scratch/main.ts:14:1

Found 6 errors.

If I swap the last two dynamic imports then it will error on validBytes instead of validText.

💻 Use Cases
  1. Implementing bytes and text imports in Deno (which will be unstable and is currently non-standard: https://github.com/whatwg/html/issues/9444)

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 bằng cách đọc logic phân giải module được trích dẫn trong src/compiler/program.ts, quanh các dòng 1973-1975, sau đó lần theo cách checker phân giải các import trong ví dụ làm cơ sở. Hoàn thành khi việc phân giải của checker có thể sử dụng node module-specifier cụ thể, để cùng một văn bản và chế độ phân giải có thể được phân giải thành các module khác nhau.

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

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Tính năng
Độ 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
42/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.