-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
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
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this