microsoft / microsoft/TypeScript
String#matchAll is too restrictive in its parameter type
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el ejemplo vinculado de TypeScript Playground; en la issue no se menciona ningún archivo del repositorio ni ninguna prueba. Rastrea la declaración utilizada por String#matchAll y compárala con la forma propuesta de MatchAllRegExpLike; después, verifica que el ejemplo compile mientras el comportamiento existente de matchAll siga estando cubierto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 43/100