microsoft / microsoft/TypeScript
Cannot import properties from module.exports as types in JSDoc
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
TypeScript Version: 3.3.0-dev.20190118
Search Terms: jsdoc import module.exports has no exported member
Code
a.js
class A {}
module.exports = {A}
b.js
// @ts-check
class B {
// In the JSDoc below, VSCode intellisense does not recognize parameter a as type A.
// Instead it shows the error:
// Namespace '".../a".export=' has no exported member 'A'
/**
* @param {import('./a').A} a
*/
constructor (a) {
this.a = a
}
}
Expected behavior
Parameter a of the constructor should be recognized as type A, which is accessible via the A property of module.exports from a.js.
Actual behavior
Intellisense reports the error: Namespace '".../a".export=' has no exported member 'A'.
Notes
@param {import('./a')} a does not give an error, but it resolves to type {A: typeof A} instead of A.
If a.js is modified with module.exports = A, then import('./a') resolves to A, however this restricts a.js to only exporting one type.
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
Führe zunächst das Beispiel mit a.js und b.js aus, wobei die JSDoc-Prüfung von TypeScript aktiviert ist. Lies nach, wie Typen aus import('./a') und module.exports behandelt werden, und überprüfe anschließend, dass die Eigenschaft A als Typ des Konstruktorparameters erkannt wird, ohne das Verhalten mit einem einzelnen Export zu ändern. Die Aufgabe ist abgeschlossen, wenn der gemeldete Fehler bei dieser Reproduktion nicht mehr auftritt.
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