| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| @@ -16,8 +14,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith | |||
|
|
|||
| class C { | |||
| x?: number; // error | |||
There was a problem hiding this comment.
comments are out of date now.
Sorry, something went wrong.
|
can you add a declaration emit test. |
Sorry, something went wrong.
|
can you also add a test with --strictNullchecks and an optional parameter property declaration, e.g. constructor(private a?: number) { } |
Sorry, something went wrong.
|
also another one for extending classes, making optionals non-optional, and making non-optionals optional. |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) Nice job! Just curious, can decorators fetch information that can determine whether the target is declared optional? |
Sorry, something went wrong.
no, see #8126 |
Sorry, something went wrong.
|
Optional class properties don't seem to work for abstract properties in typescript 2.0.3, subclasses of the abstract class are forced to implement the property. |
Sorry, something went wrong.
|
Fennec Cooper (@Roam-Cooper) that's the point of the abstract modifier, to require that an implementation is provided by a subclass. If it's optional you don't have to override it meaning it should not be abstract. |
Sorry, something went wrong.
|
Ah, yes, wasn't thinking straight! My bad. 😃 |
Sorry, something went wrong.
|
Does this PR enable making class getters optional? I can't figure out how to mark getters as optional. I have no idea where the question mark would go. |
Sorry, something went wrong.
|
Braden Snell (@bradenhs) I have the same question. Would be nice for my situation, where I want to make a custom derived class (which has getters) compatible with the base class definition/type-shape. |
Sorry, something went wrong.
|
Stephen Wicklund (@Venryx) I made an issue for this (#14417) but it was shot down. I don't think the guy reviewing the issue fully understood what I was getting at. You could create another issue and give a better explanation of the problem though. If you do let me know! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR makes it possible to declare optional properties and methods in classes, similar to what is already permitted in interfaces. For example:
When compiled in --strictNullChecks mode, optional properties and methods automatically have undefined included in their type. Thus, the b property above is of type number | undefined and the g method above is of type (() => number) | undefined. Type guards can be used to strip away the undefined part of the type: