microsoft / microsoft/TypeScript

Provide a ReadonlyRegExp type

オープン
#37,751 コメント 2 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue には実装ファイル、テスト、エントリポイントが記載されていません。まず、TypeScript が RegExp と既存の readonly 型をどのように宣言しているかを追跡し、次に、示されている replace の例に必要な宣言および互換性の変更を特定してください。完了条件は、ReadonlyRegExp 型が利用可能で、例が RegExp を想定している箇所で使用できることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。