Add simulated nominal type for COM SAFEARRAY and VarDate to lib.scripthost.d.ts #17526
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
Milestone
TypeScript Version: nightly (2.5.0-dev.20170725)
When running Javascript under an Automation context (Windows Script Host, or HTML Applications), there are two types exposed by various APIs:
VarDate
andSafeArray
. These types have no shape from Javascript's perspective:new
, andHowever, other methods/constructors/properties expect these types and will fail if an incorrect type is passed in:
Currently,
VarDate
is typed inlib.scripthost.d.ts
as an empty interface; whileSafeArray
has no defined type, and methods that expect aSafeArray
are typed withany
(example).I propose adding a representation of these types to
lib.scripthost.d.ts
:An
interface
couldn't be used here, because there is no shape from Javascript, and an empty interface is equivalent toany
The
private constructor
preventsnew VarDate();
The other private member prevents assigning an arbitrary object to a variable/parameter of this type:
Note that this is actually simulating nominal typing (thanks @Aleksey-Bykov for the suggestion). If some form of nominal typing is introduced to TypeScript, the definitions for
VarDate
andSafeArray
could be rewritten accordingly.The previous definition for
Update
could then be written as follows:VBArray
andEnumerator
could be modified to take advantage of the generic type ofSafeArray
, as in this commit.The text was updated successfully, but these errors were encountered: