Skip to content

[typescript] lib.dom.d.ts has confusing types #23595

@DovydasNavickas

Description

@DovydasNavickas

TypeScript Version: 2.8.1
VS Code Version:

Version 1.22.2
Commit 3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9
Date 2018-04-12T16:38:45.278Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

Search Terms:
useCapture
addListener
lib.dom.d.ts

Code

const htmlElement: HTMLDivElement;
htmlElement.addEventListener("scroll", event => console.log(event), true);

Before entering the last parameter (just after writing the last comma in the editor):

htmlElement.addEventListener("scroll", event => console.log(event), <----- When the cursor is here

I get code completion that looks like this:

image
And the second overload:
image
It is very confusing to see options?: boolean part not as a separate overload, but as a smushed definition of:

options?: boolean | AddEventListenerOptions | undefined

Expected behavior:
To have separate overloads for boolean version and AddEventListenerOptions one, as seen in CodeSandbox (Playground link).

Actual behavior:
Described above.

Playground Link:
https://codesandbox.io/s/r0l6j9olpn

Related Issues:
Didn't find.

The interesting thing is that while trying to reproduce the issue in CodeSandbox, I got exactly what I wanted to see: useCapture: boolean | undefined
image

So, my question is why does VS Code have a version of types that is confusing and can also be found here:
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L5450

And why CodeSandbox has a proper one? And how can we solve this?
Is this VS Code's bug or the lib.dom.d.ts bundled with TypeScript is simply out-of-date?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions