-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design Meeting Notes, 10/02/2015 #5082
Comments
@RyanCavanaugh Regarding abstract properties, see my comment about why they are actually make sense. Workaround with delegating to protected methods requires more cluttered code, and have runtime performance overhead implications. |
There is no distinction anywhere in the typeset stem between a getter/setter and a property declaration. So declaring an abstract setter for instance will not force the driver class to implement the property as a getter/setter pair. |
Today I can write: interface A {
p: number;
}
class B implements A {
get p() { ... }
set p(v: number) { ... }
} But why should not I be able to write the following then? abstract class A {
abstract p: number;
}
class B extends A {
get p() { ... }
set p(v: number) { ... }
} And forced to write the following instead: abstract class A {
get p() {
return this.getP();
}
set p(v: number) {
this.setP(v);
}
protected abstract getP(): number;
protected abstract setP(v: number): void;
}
class B extends A {
protected getP() { ... }
protected setP(v: number) { ... }
} |
The abstract class A1 {
p: number;
}
abstract class A2 {
abstract p: number;
}
abstract class A3 {
get p() { }
set p(v) {}
}
abstract class A4 {
abstract get p();
abstract set p(v);
}
abstract class A5 {
set p(v) {}
}
abstract class A6 {
abstract get p();
} all what the type system cares about is that there is a slot called 'p' on that type, and that it is a 'number'. getters/setters are not treated any differently from properties. moreover, there is no way to force a property to be implemented as getters/setter pairs. even missing a getter or a setter implementation does not affect that. thus adding the abstract keyword will not add you any additional expressiveness, it will only save you from writing the body of a getter/setter functions but will not mean what you want it to mean. see #12 for more relevant discussion about setters/getters. |
As I already said, I know that. My point is that it should be possible to force a property to be not forgotten to be implemented by any means, not necessarily with getters/setters (but of course it will be usually implemented with getters/setters): abstract class Prudent {
abstract propertyYouMustNotForgetToImplement;
}
class Forgetful extends Prudent {
// oops, I have forgotten something again
} Here a compilation error should carefully remind us to implement the property. Without And when |
not sure i understand what you mean by "implemented". properties do not really exist in the emitted code. they are just a way for the type system to know the "shape" of your type. so whether you redclare them in the child class, or not, it has no functional impact. I think what you are looking for is that the property is never |
We can implement a property by writing a custom getter/setter, or opt-out to the JavaScript default implementation, which is set/get a value associated with a key (property name) in a object.
If you redeclare (implement) a property with a getter/setter then it actually exist in the emitted code, and obviously has a functional impact.
No, it is pretty much unrelated to what I am proposing. Once more, abstract properties can make us sure that one of derived classes either implement a property with getter/setter, or consciously opt-out to the JavaScript "default implementation". abstract class A {
abstract p1;
abstract p2;
abstract p3;
abstract p4;
}
class B extends A {
get p1() { ... } // implement p1 with getter only
set p2(v: number) { ... } // implement p2 with setter only
// implement p3 with both getter and setter
get p3() { ... }
set p3(v: number) { ... }
p4; // consciously opt-out to the JS default implementation for p4
} Abstract properties can't enforce any of four alternatives above, but they can enforce that a property is consciously implemented in either way. Abstract properties should work the same way properties declared in interfaces currently work. |
Appreciate the notes, happy you guys are limiting the |
As discussed here.... #4669 An abstract property is precisely what I need for using lambda/arrow functions (as they are actually properties) "Class 'Base' defines instance member function 'def', but extended class 'Concrete' defines it as instance member property"...
|
Linting
Linting is now turned on in the CI build 🎉
Simple reachability checks
Set
to do this quicklySet
using bit masks for sets with fewer than 32 members==
, implicit;
, etc.noImplicitAny
vsallowImplicitAny
,allowUnreachableCode
vsnoUnreachableCode
implicitAny=false
?noFoo
/allowFoo
pairs?no
?abstract
enhancementsexport default abstract
(Cannot 'export default' abstract, ambient class or interface #3792)export default
is kind of like a declaration and kind of like an expressionabstract
properties (Abstract Properties #4669)abstract
classes implicitly abstractly implement their base interface (Missing property declaration in abstract class implementing interfaces #4670)class Foo { abstract static bar() { } }
abstract
classes shouldn't require asuper
call (Suggestion: pure abstract classes shouldn't require 'super' call #4429)abstract
The text was updated successfully, but these errors were encountered: