microsoft / microsoft/TypeScript

Provide a ReadonlyRegExp type

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

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

Awaiting More Feedback Suggestion
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

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

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

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.