microsoft / microsoft/TypeScript
Provide a ReadonlyRegExp type
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue non indica file di implementazione, test o punti di ingresso. Inizia tracciando il modo in cui TypeScript dichiara RegExp e i tipi readonly esistenti, quindi determina le modifiche alle dichiarazioni e alla compatibilità necessarie per l’esempio replace mostrato. Il lavoro è completato quando è disponibile un tipo ReadonlyRegExp e può essere usato dove l’esempio si aspetta un RegExp.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 30/100