microsoft / microsoft/TypeScript
Provide a ReadonlyRegExp type
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ả
Search Terms
readonlyregexp readonly regexp
Suggestion
Provide a new ReadonlyRegExp type that represents a read only RegExp.
Use Cases
This is similar to other readonly types, e.g. ReadonlyArray -- I prefer my code to be immutable by default. I have a DeepReadonly helper that could map RegExp to ReadonlyRegExp.
Note that Readonly<RegExp> does not work:
'a'.replace(/a/ as Readonly<RegExp>, 'b')
/*
No overload matches this call.
The last overload gave the following error.
Argument of type 'Readonly<RegExp>' is not assignable to parameter of type 'string | RegExp'.
Type 'Readonly<RegExp>' is missing the following properties from type 'RegExp': [Symbol.match], [Symbol.replace], [Symbol.search], [Symbol.split](2769)
*/
Examples
const emailRegExp = /[a-z]@[a-z\.]/ as ReadonlyRegExp;
export function suppressPII(message: string) {
return message.replace(emailRegExp, '');
}
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
Issue không nêu tệp triển khai, bài kiểm thử hoặc điểm vào nào. Hãy bắt đầu bằng việc lần theo cách TypeScript khai báo RegExp và các kiểu readonly hiện có, sau đó xác định những thay đổi về khai báo và khả năng tương thích cần thiết cho ví dụ replace được nêu. Được xem là hoàn tất khi kiểu ReadonlyRegExp khả dụng và có thể được sử dụng ở nơi ví dụ mong đợi một RegExp.
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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 30/100