Skip to content

Add VarDate interface and Date constructor overload for VT_DATE to lib.d.ts #9392

@zspitz

Description

@zspitz

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)

Automation host objects pass dates into Javascript as VarDate per the specification (copy found here) (section 2.2.2). These need to be wrapped in a Date constructor before they can be used in Javascript.
Such properties therefore cannot be typed as Date in declarations.

Code

namespace Scripting {
    interface File {
        DateCreated: Date;
    }
    interface FileSystemObject {
        GetFile(FilePath: string): File
    }
}
interface ActiveXObject {
    new (s: 'Scripting.FileSystemObject'): Scripting.FileSystemObject;
}

// Under WSH
var fso = new ActiveXObject('Scripting.FileSystemObject');
var file = fso.GetFile('C:\\test.txt');
var varDate = file.DateCreated;

//the following fails with "'varDate' is null or not an object"
//WScript.Echo(varDate.getYear()); 

//outputs the year
WScript.Echo(new Date(varDate).getYear());

Proposal

Add the following to scripthost.d.ts:

interface VarDate { }

interface DateConstructor {
    new (vd: VarDate): Date;
    getVarDate: () => VarDate;
}

and such date properties could use VarDate instead of Date.

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

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions