microsoft / microsoft/TypeScript

Allow specifying diagnostic code in ts-expect-error

Offen
#45,937 12 Kommentare 68 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Suggestion

🔍 Search Terms

ts-expect-error

✅ Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow @ts-expect-error to specify diagnostic codes to be more precise in expectations.
Example:
// @ts-expect-error TS1234

Will only expect that diagnostic code. If the same line triggers a different diagnostic code, the expectation will error as if there was no error on the proceeding line.

📃 Motivating Example

This feature will be particularly useful when migrating code (1) between repositories with different TS configs, or even for (2) a slightly safer path when upgrading TS versions if all issues are not immediately fixed.

💻 Use Cases

The Teams Org is facing a code migration that I expect will benefit from this greatly. Please reach out to me (or I will come to office hours) and we can go through that example.

Code

I have attached a PR which implements the change as an example. Let me know what you think!

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, den angehängten Beispiel-PR und das im Issue beschriebene bestehende Verhalten von @ts-expect-error zu überprüfen. Bestätige, wie ein Diagnosecode geparst und abgeglichen werden sollte, und füge anschließend Tests hinzu, die zeigen, dass der erwartete Code akzeptiert wird, während ein anderer oder fehlender Diagnosecode einen Fehler verursacht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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