microsoft / microsoft/TypeScript
Suggestion: stricter operators
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ả
Currently operators like "+" are defined such that they match their semantics in JS. The below are all allowed by the compiler and produce the shown values, even with --strictNullChecks on.
2 + 'a'=>"2a"null + 'a'=>"nulla"(!)2 - null=>2
I propose letting users opt in (maybe via some --strictOperators) to strict operator behavior. Concretely I think this means:
-
restrict
+, and+=to justnumberandstring, e.g. for the former only declarefunction +(a: number, b: number): number; function +(a: string, b: string): string; -
restrict
-and-=to justnumber
(any should continue to work as normal, of course.)
Relevant spec section:
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#419-binary-operators
See also "Expression operators" in the strictNullTypes change: https://github.com/Microsoft/TypeScript/pull/7140
and in particular this rationale: https://github.com/Microsoft/TypeScript/pull/7140#issuecomment-186432250
This would fall under of "stricter" TypeScript, https://github.com/Microsoft/TypeScript/issues/274 .
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 với phần Binary Operators trong doc/spec.md và thảo luận strictNullTypes được liên kết, sau đó xem xét đề xuất TypeScript chặt chẽ hơn trên diện rộng trong issue #274. Công việc sẽ hoàn tất khi một tùy chọn opt-in áp dụng các kiểu toán hạng được đề xuất cho +, +=, - và -= mà vẫn giữ nguyên mọi hành vi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, 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
- 30/100