microsoft / microsoft/TypeScript
Unable to mark JS functions as not being constructors (TS80002)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Verhalten im verlinkten TypeScript Playground mit JavaScript und TS80002 und untersuche anschließend, wie sich die JSDoc-Hinweise @this und @function auf die Erkennung von Konstruktoren auswirken. Die Aufgabe ist abgeschlossen, wenn eine unterstützte Annotation oder ein unterstützter Inferenzpfad verhindert, dass die Funktion als Konstruktor klassifiziert wird, und die erwartete Funktionsklassifizierung für die Editor-Navigation wiederherstellt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers, devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100