microsoft / microsoft/TypeScript
String#matchAll is too restrictive in its parameter type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground example; no repository file or test is named in the issue. Trace the declaration used by String#matchAll and compare it with the proposed MatchAllRegExpLike shape, then verify that the example compiles while existing matchAll behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 43/100