microsoft / microsoft/TypeScript

Warn when JSDoc type cast misses parentheses

Aperta
#28,993 1 commento 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: JSDoc In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Search Terms

jsdoc. type cast

Suggestion

JSDoc type cast currently requires parentheses for technical reasons (#18212), but it does not warn when they don't exist.

Use Cases

// This doesn't work, the JSDoc comment is silently ignored
// A warning message will help.
const img = /** @type {HTMLImageElement} */ document.getElementById('#cat')
img.src = 'cat.gif'

Examples

const img = /** @type {HTMLImageElement} */ document.getElementById('#cat')
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            ^ Warning: The JSDoc type cast misses parentheses and is being ignored
img.src = 'cat.gif'

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 con la gestione dei cast di tipo JSDoc descritta nell’issue e nell’issue referenziata #18212, quindi individua la diagnostica e i test di regressione correlati. La modifica è completa quando un cast senza parentesi produce l’avviso mostrato senza modificare l’output JavaScript, mentre i cast tra parentesi mantengono il comportamento attuale.

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

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
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.