microsoft / microsoft/TypeScript

VS Code Intellisense seems to wrongly infer revealing module pattern

Open
#18,496 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: JavaScript In Discussion Suggestion VS Code Tracked
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

From @lodybo on September 12, 2017 9:44

  • VSCode Version: 1.16.0
  • OS Version: Windows 10

Steps to Reproduce:

  1. Copy the code below into a file called greeter.js
  2. Run node greeter.js in a terminal
var Greeter = (function(country) {
  // Private
  this.country = country;

  function getCountry() {
    return country;
  }
  
  // Public
  var performGreeting = function (name) {
    var country = getCountry();
    
    return 'Hello ' + name + ', from ' + country;
  }
  
  return {
    greet: performGreeting
  }
});

var greeter = new Greeter("The Netherlands");
console.log(greeter.greet("Lody"));
console.log(greeter.country);

Using the revelealing module pattern in VS Code seems to trip up Intellisense into suggesting the wrong members. The code above was tested in multiple browsers and consoles and run with Node v6.3.0 which behaved as expected. They ran the greet() function and returned undefined for greeter.country:

λ node greeter.js
Hello Lody, from The Netherlands
undefined

But VS Code's Intellisense reports that greeter only contains country:
image

It also reports the expected interface of greeter for the class itself (Greeter):
image

What is expected is VS Code correctly inferring greeter.greet to be a function of Greeter, with a parameter name.

This was reproduced in a clean folder of VS Code, with no extensions (launched with code --disable-extensions), and no jsconfig.json.

Copied from original issue: Microsoft/vscode#34214

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided greeter.js example in VS Code IntelliSense, then compare its inferred members with the Node.js output. The work is done when IntelliSense identifies greeter.greet as a function accepting name and does not expose country as a public member.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.