Allow visibility on constructors#4174
Allow visibility on constructors#4174AbubakerB wants to merge 14 commits intomicrosoft:masterfrom AbubakerB:master
Conversation
|
Hi @AbubakerB, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
|
For this to work properly, the visibility needs to be part of the construct signature rather than being a declaration-based check that happens during signature resolution. Otherwise it's going to be too difficult to enforce assignability constraints based on constructor visibility. A relevant testcase to add would be: class Foo {
private constructor() { }
}
class Bar {
protected constructor() { }
}
let x: new() => any;
x = Foo; // Should be an error
x = Bar; // Should be an error |
|
@RyanCavanaugh SignaturesRelatedTo now checks visibility of constructor. |
|
Should i close this off? or is this in the pipeline? |
src/compiler/checker.ts
Outdated
There was a problem hiding this comment.
Can you wrap these return statements with curlies and place them on their own line?
if (!constructor || !node.expression) {
return;
}|
The declaration emitter will need to be amended - add |
|
The following test cases would be useful too: class Base {
protected constructor() {
}
}
class Derived extends Base {
private constructor() {
super();
}
}class Base {
protected constructor() {
}
}
class Derived extends Base {
protected constructor() {
super();
}
}
var baseCtor = Base;
baseCtor = Derived; |
|
@AbubakerB sorry this fell off of our radar, we've been hard at work on TypeScript 1.6. @ahejlsberg @mhegazy @vladima any thoughts? |
|
@DanielRosenwasser I see, that's fine :)
|
There was a problem hiding this comment.
Shouldn't this be new (x: number): D?
There was a problem hiding this comment.
What would be the best way of adding the new before the signature output?
I can't seem to find any method that writes 'new' + signature.
|
@AbubakerB can you get this up-to-date and resubmit in a new PR? Very sorry we left this hanging for so long. |
|
Sure. I've opened a new PR for this. |
Fixes #2341.
Changes:
1 - Allows private, protected and public accessibilities on constructors.
2 - Disallows classes with private constructors from being extended.
3 - Now throws an error on constructor overloads with different access modifiers (than the constructors implementation).