microsoft / microsoft/TypeScript
Add base class in lib.scripthost.d.ts for Automation objects
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.5.0 / nightly (2.6.0-dev.20170902)
Code
// in lib.scripthost.d.ts
class AutomationObject<T> {
private constructor();
private typekey: AutomationObject<T>;
}
// in activex-excel.d.ts
declare namespace Excel {
class Application extends AutomationObject<Application> {
Workbooks: any;
}
}
interface ActiveXObject {
new(progid: 'Excel.Application'): Excel.Application;
}
// usage
let x: Excel.Application = new ActiveXObject('Excel.Application');
This currently wouldn't compile, because of the private constructor in the base class; but pending resolution of #18283, it would be possible.
This would prevent assigning structurally matching objects to the inheriting types:
// Compiler error
x = {
Workbooks: [];
};
and also prevent using new to create a new instance of the inheriting type:
// Compiler error
x = new Excel.Application();
I've opened an issue to define similar behavior for VarDate and SafeArray<T> in lib.scripthost.d.ts. If AutomationObject<T> is defined, then it could be used in lib.scripthost.d.ts as a base class for these types as well:
declare class VarDate extends AutomationObject<VarDate> { }
declare class SafeArray<T> extends AutomationObject<SafeArray<T>> { }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib.scripthost.d.ts and review the proposed AutomationObject declaration and its use as a base for VarDate and SafeArray. Check the resolution of issues #18283 and #17526 first; done means the declarations enforce the described structural and construction restrictions without breaking the scripthost definitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100