Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zspitz opened this issue Jun 28, 2016 · 7 comments · Fixed by #9405
Closed

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

zspitz opened this issue Jun 28, 2016 · 7 comments · Fixed by #9405
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@zspitz
Copy link
Contributor

zspitz commented Jun 28, 2016

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.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 28, 2016

ActiveXObject is defined as:

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

so from the compiler perspective fso is of type any.

Contributions for better definitions for the WSH are always welcomed. the definitions should go in https://github.com/Microsoft/TypeScript/blob/master/src/lib/scripthost.d.ts

@mhegazy mhegazy added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels Jun 28, 2016
@mhegazy mhegazy added this to the Community milestone Jun 28, 2016
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Jun 28, 2016
@zspitz
Copy link
Contributor Author

zspitz commented Jun 28, 2016

Contributions for better definitions for the WSH are always welcomed.

@mhegazy I thought I was the last one using WSH (with or without Typescript)...

@mhegazy
Copy link
Contributor

mhegazy commented Jun 28, 2016

I thought I was the last one using WSH (with or without Typescript)

:D i think there still a few more out there. the TS compiler uses them internally as well to support running on cscript.

@mhegazy mhegazy modified the milestones: TypeScript 2.0, Community Jun 28, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jun 28, 2016
@zspitz
Copy link
Contributor Author

zspitz commented Jun 28, 2016

@mhegazy See here. I've written a tool that uses tlbinf32.dll to generate Typescript definitions from type libraries.

@zspitz
Copy link
Contributor Author

zspitz commented Jul 10, 2016

@mhegazy The tool is now on Github;

@zspitz
Copy link
Contributor Author

zspitz commented Sep 17, 2016

the TS compiler uses them internally as well to support running on cscript.

Are there any specific libraries that should be added?

@mhegazy
Copy link
Contributor

mhegazy commented Sep 19, 2016

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants