Skip to content

Lib files leak "support" types into global namespace #15529

Closed
@ericdrobinson

Description

@ericdrobinson

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Description

Core ECMAScript lib declaration files (e.g. lib.es5.d.ts) leak "internal" interface types into the global namespace. A common pattern employed in the lib files is that "class"-static features are placed in a [TypeName]Constructor interface and then a const variable of that type is declared with the same TypeName as the [TypeName] interface. Example:

interface Object {
    constructor: Function;
    // ...
}

interface ObjectConstructor {
    new (value?: any): Object;
    (): any;
    (value: any): any;
    // ...
}

declare const Object: ObjectConstructor;

The problem is that the ObjectConstructor type is leaked into the global namespace. No such type is defined in the ECMAScript 5.1 language spec, and yet it clutters up auto-complete suggestions.

The [TypeName]Constructor pattern seems like a workaround to enable certain features to be expressed in the lib files. The leaking of these types seems to be a side-effect of this construction.

Expected Behavior

Including a core ECMAScript lib file into a project (whether by default or compilerOption) only adds types found in the associated ECMAScript specifications into the global namespace.

Actual Behavior

[TypeName]Constructor types end up in the global namespace for any project that includes a library utilizing such a pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions