microsoft / microsoft/TypeScript

Add a specific error message for disallowed imports in project references?

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

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

Needs Proposal 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ả

Suggestion

🔍 Search Terms

project reference back import

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

After introducing project references to a monolith repo with many developers, I've sometimes seen confusion over people writing imports from projects in the incorrect direction: e.g. if project B has a tsconfig reference to project A, trying to import from B in A. ♻️

https://github.com/JoshuaKGoldberg/ts-repro-back-reference-import

Here's an example error message that says what's technically wrong but doesn't give much context:

src/a/index.ts:1:19 - error TS6307: File '---/src/b/index.ts' is not listed within the file list of project '---/src/a/tsconfig.json'. Projects must list all files or use an 'include' pattern.

1 import { b } from "../b";
                    ~~~~~~

📃 Motivating Example

Adding a specific error for these incorrect direction ("back") imports might help folks new to project references understand what they're doing wrong:

src/a/index.ts:1:19 - error TS6307: File '---/src/b/index.ts' is not listed within the file list of project '---/src/a/tsconfig.json'. Projects must list all files or use an 'include' pattern.

  File "---/b/index.ts" is included in "---/b/tsconfig.json", but "---/a/tsconfig.json" does not list a reference to "---/b/tsconfig.json".

1 import { b } from "../b";
                    ~~~~~~

💻 Use Cases

https://github.com/JoshuaKGoldberg/ts-repro-back-reference-import

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 tái hiện thao tác import back-reference trong repository ts-repro-back-reference-import được liên kết và kiểm tra các tham chiếu project trong tsconfig.json có liên quan. So sánh chẩn đoán TS6307 hiện có với ngữ cảnh bổ sung được đề xuất, sau đó xác định các vị trí trong chẩn đoán của trình biên dịch TypeScript và các test xử lý việc đưa các tệp project vào. Công việc được xem là hoàn tất khi import không chính xác tạo ra một thông báo cụ thể, có thể hành động, mà không thay đổi hành vi của các tham chiếu project hợp lệ.

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