microsoft / microsoft/TypeScript
Either understand const arrow assertions or give better errors on them
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ả
As mentioned by @threehams in https://github.com/microsoft/TypeScript/issues/35838#issuecomment-569832017, people are pretty confused about the rules for assertion functions, and I don't blame them. For example
const assert = (blah: unknown): asserts blah => { throw "hai"; }
let x: string | undefined;;
assert(x);
In our nightly releases, we give an elaboration on the declaration of assert like
'assert' needs an explicit type annotation.
For all intents and purposes, it looks like assert does have an annotation! The problem is that assert itself needs a : (x: unknown) => asserts x, because it's not automatically inferred from the arrow function.
We have two options:
-
Remove this restriction when the declaration of an assertion function is trivially detectable.
-
Make assertion function errors more clear for arrow functions:
'assert' needs an explicit type annotation. While the function it has been assigned to is fully annotated, the variable declaration for 'assert' does not.
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
Không có tệp repository hoặc test nào được nêu. Hãy tái hiện ví dụ const arrow assertion từ issue trong một bản build nightly của TypeScript, sau đó kiểm tra đường dẫn chẩn đoán assertion-function hiện có. Được xem là hoàn tất khi các arrow assertion có thể phát hiện một cách hiển nhiên được chấp nhận hoặc chẩn đoán giải thích rằng bản thân khai báo biến thiếu type annotation tường minh bắt buộc.
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