microsoft / microsoft/TypeScript
Suggestion: add flag to notify when awaiting a non-promise
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ả
Search Terms
async promise force error
Suggestion
Add a tsconfig.json flag to display info/warning/error when awaiting non-PromiseLike code. This will catch developer errors.
Use Cases
Catch developer errors when writing async code.
Example
The following code is valid:
await Promise.all(urls.map(url => {
fetch(url);
});
console.log('fetching complete');
The developer intends to do something once all the fetches complete, but since map is not returning any value, it ends up awaiting [undefined, undefined, ...], which means fetching complete is logged before the fetches complete. It would be nice if TS gave an info/warning/error in this case.
The correct code is:
await Promise.all(urls.map(url => {
return fetch(url);
});
console.log('fetching complete');
This example is paired down to the bare minimum for simplicity, but IRL code is more complex.
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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
Vì issue không xác định tệp nguồn hoặc bài kiểm thử nào, hãy bắt đầu bằng việc tìm hiểu cách TypeScript xử lý các biểu thức await và các chẩn đoán của tsconfig. Công việc được hoàn tất khi đã định nghĩa và triển khai một info, warning hoặc error có thể cấu hình cho việc await mã không phải PromiseLike, kèm theo độ bao phủ cho ví dụ Promise.all được cung cấp.
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
- 35/100