microsoft / microsoft/TypeScript

String#matchAll is too restrictive in its parameter type

Aperta
#55,843 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

matchAll

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about RegExps and matchAll
⏯ Playground Link

https://www.typescriptlang.org/play?target=7#code/MYewdgzgLgBAtgTwMIFdojgeQEYCsCmwsAvDAN4CwAUDLTAFQDaAygnNiADYB0cAhlGAALAIKdOAXQAU0AE4BLMAHMAXDDmKlASjUBxfGHyyBIWQB4ASviUBRAB4AHe4RGzjCAHzlqdGAF9qAKpqUEgufG5OECUpRm54gHIAMxAQBN4BYTFOKURUdCw8QigtCS0AbmogA

💻 Code
const myCustomObject = {
    *[Symbol.matchAll](string: string): Generator<RegExpExecArray> {
    }
}

console.log([...'foo'.matchAll(myCustomObject)]);
🙁 Actual behavior

TS rejects this code, because myCustomObject is not an instance of RegExp.

🙂 Expected behavior

Any value matching the following type should be accepted, including myCustomObject. The other parts of the RegExp object are not used.

type MatchAllRegExpLike = {
  [Symbol.matchAll](string: string): IterableIterator<RegExpExecArray>;
  // If the object has a [Symbol.match] property that is truthy, its flags are checked. However, neither
  // must be present, and even if it is present, [Symbol.match] doesn't have to be a function.
  readonly [Symbol.match]?: any;
  readonly flags?: string;
};
Additional information about the issue

This is distinct from #47310. That issue is about string-to-regexp conversion; this is about regexp-like objects.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l'esempio collegato di TypeScript Playground; nell'issue non sono indicati file del repository né test. Segui la dichiarazione utilizzata da String#matchAll e confrontala con la forma proposta di MatchAllRegExpLike, quindi verifica che l'esempio venga compilato mentre il comportamento esistente di matchAll rimane coperto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
43/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.