microsoft / microsoft/TypeScript

Checking JS types does not accept @implements or @augments on constructor functions

Offen
#38,985 2 Kommentare 19 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

TypeScript Version: 3.9.5 (also tested on 3.9.3 initially)

Search Terms: @implements, jsdoc

Code

/**
 * @param {string} name
 * @implements {EventTarget}
 * @constructor
 */
function Foo (name) {
  this.name = name
}

/**
 * @param {string} type
 * @param {EventListenerOrEventListenerObject} listener
 * @param {boolean | AddEventListenerOptions} [options]
 */
Foo.prototype.addEventListener = function (type, listener, options) {}

Then run tsc --noEmit --checkJS --allowJS reproducer.js

Expected behavior:

According to https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#constructor-functions-are-equivalent-to-classes, constructor functions are treated like classes. So using @implements or @augments on them should be possible. It used to work in the past.

Actual behavior:

reproducer.js:6:10 - error TS8022: JSDoc '@implements' is not attached to a class.

6 function Foo (name) {
           ~~~


Found 1 error.

Playground Link: I was not able to reproduce this in the playground (but it does not have the latest 3.9 versions available)

Related Issues:

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem reproducer.js-Beispiel und führe tsc --noEmit --checkJS --allowJS reproducer.js mit der betroffenen TypeScript-Version aus. Verfolge die Verarbeitung von JSDoc @implements und @augments bei Konstruktorfunktionen; abgeschlossen ist die Aufgabe, wenn die Annotationen ohne TS8022 akzeptiert werden und die bestehenden JavaScript-Prüfungen weiterhin gültig sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.