Class properties#59
Class properties#59fizker wants to merge 2 commits intoniieani:masterfrom fizker:private-class-properties
Conversation
…MAScript and flow supports it as well
|
This compares type-checked private properties with runtime private properties - they're different, so this PR isn't accurate to that. We can make a separate section about runtime private properties. |
|
That's not true. The current version incorrectly claims that Flow does not support the concept of both public and private properties; it most certainly does, and it enforces this on a static type-checking level, same as TypeScript. The actual runtime code is dependent on the compiler used and have nothing to do with Flow nor with static type-checking. There are probably other things that work fine at runtime even though it fails at type-checking time, such as read-only objects and exact objects. They are not mentioned anywhere, so I don't see the point of mentioning this either. I can rewrite it to split the public and private properties apart. This makes sense since the two systems share the syntax for public properties, with the exception of some syntactic sugar that TypeScript supports. The part for the private properties could get a note describing that TypeScript does not have actual private properties, if that seems appropriate. But then we move into runtime parts, which seems out of scope of this article. |
- Put the public class properties under the shared-syntax header - Rewrote the private part to be more to-the-point
There was a problem hiding this comment.
There's a distinction between TC39 private fields proposal, and private field type annotation in TypeScript. The PR mixes these two.
TypeScript supports:
- TC39 private fields (fields with
#, not transpiled in runtime) privatefield type annotations (type-annotations only, not affecting emit)
While flow supports:
- TC39 private fields (fields with
#, not transpiled in runtime) - munged underscored fields (fields starting with
_are treated as private, type-annotations only, not affecting emit)
We should compare:
- the first of both (it's identical, so 'same syntax')
- the second of both
|
|
||
| ## Private properties in classes | ||
|
|
||
| ### flow |
There was a problem hiding this comment.
The example below isn't flow specific. It works the same way as in TypeScript.
There was a problem hiding this comment.
If this could be specified as "same syntax" (without separation), then I'll accept.
| } | ||
| ``` | ||
|
|
||
| ### TypeScript |
There was a problem hiding this comment.
This example can be removed, or moved to the part below (above Object callable property), since it duplicates the part that starts with:
Also, TypeScript have some syntactic sugar for setting the props through the constructor
Moved the section out of TS-only, since both ECMAScript and flow supports it.