Skip to content

Commit

Permalink
update conventions and "private to file" and "readonly publicly", phe…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Mar 23, 2022
1 parent d0eafbe commit 26f71f1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/typescript-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ class Clock {
}
```

The `private` modifier behaves differently than PhET's JavaScript JSDoc `@private` annotation. In typescript, this is
private to the class, and often in JavaScript it meant "private to the file." To get around this, it is often helpful
to convert a function/constant/etc. that needs to use the `private` feature of the class to be a `private static` member
of the class itself.

For `readonly`, TypeScript's support also differs from how this was used in JavaScript code at PhET. At PhET it was
common to mark something as readonly if internal class logic changed the value, but publicly, it was readonly. To support
this in TypeScript, create two members in the class that point to the same value/field/member, one marked as `private`,
and the other as `public readonly`.

### Enumerations

Please see https://github.com/phetsims/wilder/blob/master/js/wilder/model/WilderEnumerationPatterns.ts
Expand Down

0 comments on commit 26f71f1

Please sign in to comment.