microsoft / microsoft/TypeScript

Either understand const arrow assertions or give better errors on them

Đang mở
#36,067 2 bình luận 27 reaction 0 người được giao Xem trên GitHub

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

Domain: Error Messages Experience Enhancement In Discussion Rescheduled 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ả

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

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

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

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.