microsoft / microsoft/TypeScript

Module.exports = {} not recognized by IntelliSense

Offen
#31,928 3 Kommentare 7 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.5.1

The CommonJS construct module.exports = {} does not provide import suggestions in JS files via VSCode IntelliSense.

IntelliSense provides a TS error handle on the module.exports = {} construct:

File is a CommonJS module; it may be converted to an ES6 module.ts(80001)

Pressing the Quick Fix option converts the exports to ES6 format. After this, IntelliSense import suggestions work in other scripts.

What also works is formatting the export as follows:

module.exports.showText = showtext;

My files are:

lib.js

function showText() {
  console.log('Text');
}

module.exports = {
  showText: showText,
}

myCode.js

showTe...;  // <- no import suggestion provided

Project structure:

./lib.js
./myCode.js

I would like to get the IntelliSense import suggestion without change of the module.exports = {} construct (I do not have the authorization to do this for the entire project code base).

I am not using a jsconfig.json file.

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

Reproduziere das Verhalten mit den bereitgestellten Dateien lib.js und myCode.js, verwende module.exports = {} und überprüfe die Importvorschläge für showText in myCode.js. Untersuche das IntelliSense-Verhalten für dieses CommonJS-Muster; abgeschlossen ist die Aufgabe, wenn der Vorschlag erscheint, ohne den Export in die ES6-Syntax umzuwandeln oder das Format seiner Eigenschaften zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript, vscode
Bereich
developer-experience, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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