microsoft / microsoft/TypeScript
Allow class inheritance in ambient contexts, even with a base private constructor
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: nightly (2.5.0-dev.20170902)
Code
declare namespace Foo {
class Bar {
private constructor();
Box: string;
}
class Baz extends Bar {
private constructor();
}
function generator(): Baz;
}
let x = Foo.generator();
x.Box = 'abcd';
Expected behavior:
Compile without error.
Actual behavior:
error TS2675: Cannot extend a class 'Foo.Bar'. Class constructor is marked as private.
Use case
This would allow declaring the types of host-supplied objects, with the following features:
- can inherit members from each other
- cannot be inherited from using standard Typescript/Javascript classes
- cannot be assigned to from an object literal with matching members
- cannot be constructed, only returned from a factory method
declare namespace com.sun.star.text {
class XTextTablesSupplier {
private constructor();
private typekey: XTextTablesSupplier;
readonly TextTables: any;
}
class GenericTextDocument extends XTextTablesSupplier {
private constructor();
private typekey1: GenericTextDocument;
CharacterCount: number;
}
}
declare function createInstance(typename: 'com.sun.star.text.GenericTextDocument'): com.sun.star.text.GenericTextDocument;
let x = createInstance('com.sun.star.text.GenericTextDocument'); // OK
x = new com.sun.star.text.GenericTextDocument(); // Error
let y = x.TextTables; // OK
// The following would be an error
x = {
TextTables: '',
CharacterCount: 5
};
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 by compiling the ambient namespace example from the issue with the referenced TypeScript nightly behavior. Trace the checker diagnostic for extending Foo.Bar and compare it with the expected acceptance of the declaration. Done means the example compiles while construction and object-literal assignment remain errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100