microsoft / microsoft/TypeScript

Compiler error message improvement: Special casing container objects

Abierto
#35,141 0 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Experience Enhancement Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

Search Terms

array promise container error message compare

Suggestion

Could it be worth having an extra special case message when the only difference is that you haven't included an array indicator instead of listing the property differences e.g.

3.7:

src/index.ts:356:5 - error TS2322: Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }[][]' is not assignable to type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }[]'.
      Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }[]' is missing the following properties from type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }': renderedMessage, id, category, code, start

    356     errors,
            ~~~~~~

      src/index.ts:235:3
        235   errors: {
              ~~~~~~
        The expected type comes from property 'errors' which is declared here on type 'TwoSlashReturn'

To:

src/index.ts:356:5 - error TS2322: Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; length: number | undefined; }[][]' is not assignable to type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; length: number | undefined; }[]'.

Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; length: number | undefined; }[]' is in an array here:

    356     errors,
            ~~~~~~

      src/index.ts:235:3
        235   errors: {
              ~~~~~~
        But not here

and the reverse?

Use Cases

Any case of mismatched types where the difference is that the object on one side of the comparison is the same object but wrapped in an array. Perhaps this could also work for a Promise too?

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

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

Empieza reproduciendo el ejemplo de array-mismatch y el ejemplo enlazado de Promise en el TypeScript playground. El issue no indica archivos del compilador ni tests, así que, después de establecer la salida actual, sigue la ruta de generación de diagnósticos; la tarea estará terminada cuando estén cubiertos los diagnósticos específicos del contenedor solicitados sin cambiar el comportamiento en tiempo de ejecución.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.