microsoft / microsoft/TypeScript

Improve error message for @ts-expect-error directive

Aperta
#54,008 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Proposal Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

I've just been looking for a way to "unit test" some quite complicated generic type signatures, and have just come across the @ts-expect-error and @ts-expect-no-error directives, which I think are fantastic for this kind of use case.

However, if I do something like this:

let myVar = 'bob';

// @ts-expect-error
myVar = 'fred';

The actual error I get is "Unused '@ts-expect-error' directive".

This makes it look as though the directive has been used incorrectly (which obviously it has in this very simple example), but this seems like it will be confusing for anyone subsequently involved in maintaining my code - because it looks as though all they need to do is remove the directive in order to fix the problem, whereas generally speaking, I will have put the directive there for a good reason, and if it's "unused" it means that somebody has broken the type signature logic.

Please could this error message be changed to shift the emphasis more onto the code being wrong, rather than the directive needing to be removed?

E.g.: "'@ts-expect-error' directive - this code should have failed type-checking, but didn't"

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 individuando la diagnostica che segnala "Unused '@ts-expect-error' directive" e ispeziona i test del compilatore correlati, se presenti. Aggiorna la formulazione in modo da sottolineare che il codice annotato ha superato inaspettatamente il controllo dei tipi, quindi verifica che l'esempio produca la diagnostica aggiornata.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.