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.
TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
Automation host objects pass dates into Javascript as
VarDateper the specification (copy found here) (section 2.2.2). These need to be wrapped in aDateconstructor before they can be used in Javascript.Such properties therefore cannot be typed as
Datein declarations.Code
Proposal
Add the following to scripthost.d.ts:
and such date properties could use
VarDateinstead ofDate.