Open
Description
🔎 Search Terms
RegExp, matchAll, Symbol.matchAll, RegExpExecArray, RegExpMatchArray
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about RegExp, matchAll, Symbol.matchAll, RegExpExecArray, RegExpMatchArray
⏯ Playground Link
💻 Code
const re = /./g
const str = 'abc'
for (const m of str.matchAll(re)) {
// ok (expected result)
const i: number = m.index
}
for (const m of re[Symbol.matchAll](str)) {
// Type 'number | undefined' is not assignable to type 'number'.
const i: number = m.index
}
🙁 Actual behavior
While String#matchAll
now correctly returns RegExpStringIterator<RegExpExecArray>
(#36788, fixed in #55565), the identically-behaving RegExp#[Symbol.matchAll]
still returns the incorrect type RegExpStringIterator<RegExpMatchArray>
🙂 Expected behavior
String#matchAll
and RegExp#[Symbol.matchAll]
to behave identically at compile time as well as runtime, i.e. both String#matchAll
and RegExp#[Symbol.matchAll]
to consistently return RegExpStringIterator<RegExpExecArray>
.
Additional information about the issue
No response