microsoft / microsoft/TypeScript
Add missing `toString` declarations for base types that have them
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
Search Terms
toString, RegExp, Regular Expression, Boolean, Error
Suggestion
In @typescript-eslint, we have a rule no-base-to-string. This rule ensures that any value that's being coerced to a string has a toString method defined on it.
This is to help catch cases where you accidentally coerce something to a string, and end up with an [object Object] in your strings.
This rule has a pretty simple implementation - it just gets the declarations of the toString method on the type, and ensures that none of the declarations belong to the Object type.
The logic relies upon the fact that every type that actually has a toString method explicitly declares a toString method.
A few of our users ran into cases that were reporting errors for them, even though they shouldn't (https://github.com/typescript-eslint/typescript-eslint/issues/1655).
There's one that specifically has caused people some issues: Boolean/boolean.
I eyeballed the docs and the types, and I am pretty certain there are only 3 types that are missing a toString declaration:
- RegExp: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString
- Boolean: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString
- Error: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString
Related
PR: #37839
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 localizando las declaraciones de la biblioteca estándar para RegExp, Boolean y Error y compara sus miembros existentes con los built-ins correspondientes de JavaScript. Confirma que cada declaración de toString que falta esté representada en los tipos y verifica el cambio con la suite de pruebas de TypeScript correspondiente; se considera terminado cuando los tres tipos declaran explícitamente el método sin cambiar el JavaScript emitido.
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
- Nueva funcionalidad
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100