Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp#[Symbol.matchAll] should return iterable of RegExpExecArray instead of RegExpMatchArray #60515

Open
lionel-rowe opened this issue Nov 16, 2024 · 0 comments · May be fixed by #60516
Open

Comments

@lionel-rowe
Copy link
Contributor

🔎 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

https://www.typescriptlang.org/play/?target=99#code/MYewdgzgLgBATgUxgXhgegHRoOYChSSzRwowDkAhgEbBm64BmIJAFAdDALYwgMzEZOFKMAAWAQQA2klogCUcmAG9cMNejQ8A1jBYIAHgAcEwKAgAm8BBACukqHNXr2sAJYAuGGBucqCEqicGK5g5gbqMLgAvvRMrC5cPHyIANoAygCeviCSgsJiUpIAuizECspOamiaACoZxuTevv4wAD4wNqEIDCEWZDCuEF4gsBQQEK7YYNSSSFAgMFD1SGRNfnBkGJUwCR5ePuukQSFh+tG4QA

💻 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant