microsoft / microsoft/TypeScript
String#matchAll is too restrictive in its parameter type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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.
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
Beginne mit dem verknüpften TypeScript Playground-Beispiel; in der Issue wird keine Repository-Datei und kein Test genannt. Verfolge die von String#matchAll verwendete Deklaration und vergleiche sie mit der vorgeschlagenen Form von MatchAllRegExpLike; überprüfe anschließend, dass das Beispiel kompiliert, während das bestehende matchAll-Verhalten weiterhin abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 43/100