Skip to content

Commit

Permalink
Merge pull request #1081 from mobxjs/fix-1077-observe
Browse files Browse the repository at this point in the history
Make sure fields are initialized before observing them, fixes #1072
  • Loading branch information
mweststrate authored Jul 6, 2017
2 parents 1690b9c + 4286b0e commit cd0214b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 3.1.17

* Improved typings of `IObservableArray.intercept`: use more restrictive types for `change` parameter of `handler`, by @bvanreeven
* Fixed [#1072](https://github.com/mobxjs/mobx/issues/1072), fields without a default value could not be observed yet when using TypeScript

# 3.1.16

Expand Down
2 changes: 2 additions & 0 deletions src/types/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export function getAtom(thing: any, property?: string): IDepTreeNode {
}
// Initializers run lazily when transpiling to babel, so make sure they are run...
runLazyInitializers(thing);
if (property && !thing.$mobx)
thing[property]; // See #1072 // TODO: remove in 4.0
if (isObservableObject(thing)) {
if (!property)
return fail(`please specify a property`);
Expand Down
10 changes: 10 additions & 0 deletions test/typescript/typescript-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,13 @@ test("803 - action.bound and action preserve type info", t => {
const bound2 = action.bound(function () {}) as (() => void)
t.end()
})

test("1072 - @observable without initial value and observe before first access", t => {
class User {
@observable loginCount: number;
}

const user = new User();
observe(user, 'loginCount', () => {});
t.end()
})

0 comments on commit cd0214b

Please sign in to comment.