microsoft / microsoft/TypeScript
Declare type to be an import depending on a string literal argument: typeof import(name);
Chưa có ai nhận issue này.
- 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ả
Hello,
It's seems to be difficult to do but there's now a lot of possibilities with the typescript compiler that I wouldn't have thought possible before, so I prefer to ask.
Is there a chance to have this kind of definition:
declare function require(name: string): typeof import(name) | undefined;
I mean declaring the return type as the type coming from the import of module "name". So we could have the type returned by require:
var module = require("my module");
I guess if it's feasible, it will also be possible to add more typing on this kind of javascript code
define("myModule, ["deps1", "deps2", "deps3"], (deps1, deps2, deps3) => {
// deps1, deps2, deps3 have the right type !!
});
like this
define("myModule, ["deps1", "deps2", "deps3"], (deps1: typeof import("deps1"), deps2: typeof import("deps2"), deps3: : typeof import("deps3")) => {
// deps1, deps2, deps3 have the right type !!
});
Thanks for your help,
--
Laurent
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 việc điều tra xem trình biên dịch TypeScript có thể làm cho typeof import(name) phụ thuộc vào một literal chuỗi và sử dụng kết quả đó cho các lời gọi require và define hay không. Xem lại các ví dụ của issue và xác định những thay đổi cần thiết đối với ngôn ngữ và việc kiểm tra kiểu; công việc được xem là hoàn tất khi các kiểu module được yêu cầu được suy luận từ các đối số literal.
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
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100