microsoft / microsoft/TypeScript

Compiler error message improvement: Special casing container objects

Aperta
#35,141 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Experience Enhancement Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l’esempio di array-mismatch e l’esempio collegato di Promise nel TypeScript playground. L’issue non indica file del compilatore né test, quindi, dopo aver stabilito l’output attuale, segui il percorso di generazione dei diagnostici; il lavoro è completato quando i diagnostici specifici per il container richiesti sono coperti senza modificare il comportamento a runtime.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.