microsoft / microsoft/TypeScript

String#matchAll is too restrictive in its parameter type

Abierto
#55,843 1 comentario 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
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

https://www.typescriptlang.org/play?target=7#code/MYewdgzgLgBAtgTwMIFdojgeQEYCsCmwsAvDAN4CwAUDLTAFQDaAygnNiADYB0cAhlGAALAIKdOAXQAU0AE4BLMAHMAXDDmKlASjUBxfGHyyBIWQB4ASviUBRAB4AHe4RGzjCAHzlqdGAF9qAKpqUEgufG5OECUpRm54gHIAMxAQBN4BYTFOKURUdCw8QigtCS0AbmogA

💻 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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.