microsoft / microsoft/TypeScript
String#matchAll is too restrictive in its parameter type
Nessuno ha ancora preso questa issue.
- 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
💻 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
- 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
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