microsoft / microsoft/TypeScript
Provide a ReadonlyRegExp type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Implementierungsdateien, Tests oder Einstiegspunkte. Beginne damit nachzuverfolgen, wie TypeScript RegExp und vorhandene readonly-Typen deklariert, und ermittle dann die für das gezeigte replace-Beispiel erforderlichen Deklarations- und Kompatibilitätsänderungen. Als erledigt gilt die Aufgabe, wenn ein ReadonlyRegExp-Typ verfügbar ist und dort verwendet werden kann, wo das Beispiel einen RegExp erwartet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 30/100