microsoft / microsoft/TypeScript
Unable to mark JS functions as not being constructors (TS80002)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Bug Report
TS80002 ("This constructor function may be turned to a class declaration") is a useful tool, but, it often breaks syntax coloring and classification of functions for things like out-of-line event handlers. There seems to be no way to mark a function as "not a constructor" (would the @function JSDoc hint maybe serve this purpose?)
🔎 Search Terms
jsdoc typescript constructor ts80002
🕗 Version & Regression Information
- This behavior was introduced after 3.6.2 at some point, and I reviewed the FAQ for entries about TS80002.
⏯ Playground Link
Playground link with relevant code
💻 Code
/**
* @this {HTMLElement}
* @param {MouseEvent} e
*/
function test(e)
{
this.textContent = '500';
}
document.addEventListener('click', test);
🙁 Actual behavior
TypeScript marks the function test as a constructor for a type. As a consequence, too, VSCode marks it as a type, and not a function, which is confusing for navigation purposes.
🙂 Expected behavior
TypeScript should be able to detect that with a @this hint (or @function perhaps?) that this isn't a constructor.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riprodurre il comportamento nel TypeScript Playground collegato con JavaScript e TS80002, quindi analizzare in che modo le indicazioni JSDoc @this e @function influenzano il rilevamento dei costruttori. Il lavoro è completato quando un’annotazione supportata o un percorso di inferenza supportato impedisce che la funzione venga classificata come costruttore e ripristina la classificazione della funzione prevista per la navigazione nell’editor.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers, devtools
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100