Typescript: clearTimeout is imported from timers

Created on 2 Apr 2019  ·  8Comments  ·  Source: microsoft/TypeScript

  • VSCode Version: 1.32.3
  • OS Version: Windows 10

Steps to Reproduce:

  1. Write clearTimeout
  2. You get import { clearTimeout } from 'timers' imported without asking and error in the browser.

Reported here already:
https://github.com/Microsoft/vscode/issues/57822
https://github.com/Microsoft/vscode/issues/40001
https://github.com/Microsoft/vscode/issues/38911

Is it impossible for VS Code to know that I write code for a browser where these are available already, and should not import them?


Does this issue occur when all extensions are disabled?: Yes/No - no idea

Bug Fix Available Fixed

Most helpful comment

Yes I have this one: "editor.suggest.localityBonus": true,

Right now I have re-enabled the import setting and like you said, the globals are now on top of the list. The auto import was on top at the time I opened this issue, so that is fixed.

Still, I think that there shouldn't be so confusing imports shadowing globals like in the following image:
image

I am not sure which setting is responsible for the auto import in a .vue file component in a project without TypeScript. For this test I enabled all 3 of them (temporarily).

  "typescript.suggest.autoImports": true,
  "javascript.suggest.autoImports": true,
  "vetur.completion.autoImport": true,

All 8 comments

I think this is a duplicate of #15024.

I don't think it's a duplicate of #15024 because that issue says to favor local variables while this issue is about why existing global properties of the window object are being shadowed with something auto imported. This was and will be reported probably in the future because it doesn't seem like there is any interest in fixing this.

I see both in my completion list, which is probably even worse (since it's hard to tell them apart). If something in the lexical scope exists, we shouldn't offer it at all as an auto-import

this is how i do it:

window.setTimeout(...) // <-- right signature is picked

it's back to the question about annoying ambients https://github.com/Microsoft/TypeScript/issues/14306

https://github.com/palantir/tslint/issues/922

@csicky I'm trying to track down how and when the worst-case scenario is happening. Like Ryan, I see both completions, and the global one is always the top one and always selected, so for me, clearTimeout never gets accidentally imported because I have to press the down arrow key to select the auto-import. Could you help me try to reproduce your exact problem?

  1. You're writing JavaScript, not TypeScript, correct?
  2. Is there a tsconfig.json file anywhere in your project?
  3. What do you see when you start typing clearTimeout? Here’s what I see:
    Screen Shot 2019-04-30 at 6 32 36 AM
  4. In VS Code, if you open the command palette and select “Preferences: Open Settings (JSON),” are there any options you have set that begin with editor.suggest?

Yes I have this one: "editor.suggest.localityBonus": true,

Right now I have re-enabled the import setting and like you said, the globals are now on top of the list. The auto import was on top at the time I opened this issue, so that is fixed.

Still, I think that there shouldn't be so confusing imports shadowing globals like in the following image:
image

I am not sure which setting is responsible for the auto import in a .vue file component in a project without TypeScript. For this test I enabled all 3 of them (temporarily).

  "typescript.suggest.autoImports": true,
  "javascript.suggest.autoImports": true,
  "vetur.completion.autoImport": true,

For public visibility: I do have a PR up at #31065, but I don't like it very much. Given this:

the globals are now on top of the list. The auto import was on top at the time I opened this issue, so that is fixed.

I've changed the milestone to 3.6 and plan to revisit this and see if we can come up with some better heuristics after 3.5 is released.

Woops, this should have been closed with #31893. The "fixed" label kept it from showing up in my usual query.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  ·  3Comments

kyasbal-1994 picture kyasbal-1994  ·  3Comments

blendsdk picture blendsdk  ·  3Comments

manekinekko picture manekinekko  ·  3Comments

siddjain picture siddjain  ·  3Comments