microsoft / microsoft/TypeScript

Allow specifying diagnostic code in ts-expect-error

Aperta
#45,937 12 commenti 68 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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!

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 esaminando la PR di esempio allegata e il comportamento esistente di @ts-expect-error descritto nell’issue. Conferma come deve essere analizzato e confrontato un codice diagnostico, quindi aggiungi test che dimostrino che il codice previsto viene accettato, mentre una diagnostica diversa o mancante causa un errore.

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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.