Unable to mark JS functions as not being constructors (TS80002)

Aperta
#43,812 5 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, typescript

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.

Descrizione

Awaiting More Feedback Suggestion

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.

Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 15h
PR unite (30g)
106

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.

Altre issue di microsoft/TypeScript

Tutte le issue di microsoft/TypeScript

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.