microsoft / microsoft/TypeScript
Always verify import path
Chưa có ai nhận issue này.
- 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ả
In many projects is necessary work with files which isn't a TS/JS file. Some common ones are png, jpg, svg, but when importing this files we get Cannot find module or its corresponding type declarations. error.
Searching how to fix that, we come across many discussions suggesting using the global module declaration, such as:
declare module '*.svg' {
const content: string
export default content
}
Links
- Importing images in TypeScript React - “Cannot find module”
- Webpack & Typescript image import
- Typescript image import
- TypeScript "Cannot find module './myFile..." for .scss, .less, images files, wasm...
- Importing SVG files as React Components in TypeScript
This approach fix the lint error, but disable TS intellisense.
Example
Folder structure
app
|
├ img
| └─ top-view.svg
|
└─index.ts
index.ts

No errors, but the correct path is ../img/top-view.svg
Here is the related issue #40333
Suggestion
Compiler could still returning missing type declarations for not TS/JS files. But always check if import path results in a file and return an error if not (even if file is not an TS/JS).
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 issue liên quan #40333 và các ví dụ trong báo cáo này, sau đó điều tra hành vi phân giải đường dẫn import của TypeScript đối với các tệp không phải TS/JS. Công việc được xem là hoàn tất khi hành vi chẩn đoán tệp bị thiếu được đề xuất đã được xác định và triển khai mà không làm mất hỗ trợ cho các module non-code đã khai báo.
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ó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- 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
- 25/100