microsoft / microsoft/TypeScript
jsconfig.json gives broken intellisense for js files with module.exports
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
- VSCode Version: 1.38.0
- TS Version: 3.6.2
- OS Version: Ubuntu 18.04 LTS bionic beaver
- Tested with no extensions
- Can not really find a solution to this problem after a lot of searching
I have a personal js library that I use both in browser-side and node-side for a lot of my personal projects . In fact the library itself has its own project . The js library looks like this :
const library = {};
library.foo = function() {/*browser code*/}
if (typeof module === 'object') {
library.bar = function() {/*node code*/}
module.exports = library;
}
For a browser project (library is used via script tag) If I try to get intellisense via jscofig.json for such a file I get broken intellisense (by typing f or b I get suggestions for foo or bar respectively , but there is no library suggestion when I type l , and even if I type library I get no suggestion about its properties ) .
For a node project everything works fine regarding intellisense using require .
The issue here is with module.exports . If I change it to var substitute = module; substitute.exports = library; then I get intellisense for browser project via jsconfig.json but broken intellisense (as described before) for node via require .
How can I get intellisense to work for both require and jsconfig.json ?
Before you attempt to check intellisense you should know the following :
I open index.js in a project that does not have any other js file and no
jsconfig.jsonfile . Then I view in the same VScode session some other , completely unrelated to my project , js files . For whatever file I view I get intellisense (of the globally scoped variables that have been defined vialet,varorconst) when I am editing index.js . If the unrelated js file happens to have module.exports then the intellisense that I get in index.js for that file is broken like it has been described before .
I stop getting intellisense for files that I view when I create ajsconfig.jsonfile file in the folder of index.js . But still there is the same broken behavior with intellisense for files that are included viajsconfig.jsonand have module.exports .
Please restart vscode to test if intellisense really works .
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Reproduisez le comportement dans VSCode 1.38.0 avec TypeScript 3.6.2 en utilisant le fichier index.js présenté, jsconfig.json, l’utilisation dans le navigateur et l’utilisation de Node require. Comparez IntelliSense pour module.exports direct avec l’alias de substitution, et considérez l’issue comme terminée lorsque jsconfig.json et require fournissent tous deux la bibliothèque et ses propriétés de manière cohérente.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript, vscode
- Domaine
- developer-experience, tooling
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100