microsoft / microsoft/TypeScript

Improve error message for @ts-expect-error directive

Offen
#54,008 4 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs Proposal Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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"

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die Diagnose zu finden, die "Unused '@ts-expect-error' directive" meldet, und untersuche die zugehörigen Compiler-Tests, falls vorhanden. Aktualisiere die Formulierung so, dass sie hervorhebt, dass der annotierte Code unerwartet die Typprüfung bestanden hat, und überprüfe anschließend, dass das Beispiel die überarbeitete Diagnose erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.