Skip to content

Enable possibility of strong typing on ActiveXObject via specialized overloads #2541

Description

@zspitz

If I've defined an interface corresponding to an Automation object:

module Scripting {
    interface FileSystemObject {
        BuildPath(Path: string,Name: string): string
        FileExists(FileSpec: string): boolean
        //other members ...
    }
}

it should be possible to get the type as said interface, using type inference and specialized overloads:

var fso = new ActiveXObject('Scripting.FileSystemObject');

This could be done by having ActiveXObject implement a named interface in lib.d.ts:

interface ActiveXObject {
    new (s: string): any;
}
declare var ActiveXObject: ActiveXObject;

Then, other modules could add the additional specialized overloads:

interface ActiveXObject {
    new (s: 'Scripting.FileSystemObject'): Scripting.FileSystemObject;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions