-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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.
lionel-rowe
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript