From 413925fe8e847c6898c8231808ecc127f55df528 Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Wed, 23 Aug 2017 21:55:51 +0300 Subject: [PATCH 1/2] @action get func(){} have accurate error messages --- .flowconfig | 1 + src/api/action.ts | 3 +++ test/babel/babel-tests.js | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/.flowconfig b/.flowconfig index 41afc31ab..5488fc4dc 100644 --- a/.flowconfig +++ b/.flowconfig @@ -6,6 +6,7 @@ test/flow [libs] flow-typed/ +node_modules/mobx/lib/mobx.js.flow [options] suppress_comment= \\(.\\|\n\\)*\\$ExpectError diff --git a/src/api/action.ts b/src/api/action.ts index 9057df5e9..b80858760 100644 --- a/src/api/action.ts +++ b/src/api/action.ts @@ -120,6 +120,9 @@ function namedActionDecorator(name: string) { descriptor.configurable = true return descriptor } + if (descriptor !== undefined && descriptor.get !== undefined) { + throw new Error("[mobx] action is not expected to be used with getters"); + } // bound instance methods return actionFieldDecorator(name).apply(this, arguments) } diff --git a/test/babel/babel-tests.js b/test/babel/babel-tests.js index e3de48496..3a40b915f 100644 --- a/test/babel/babel-tests.js +++ b/test/babel/babel-tests.js @@ -56,6 +56,17 @@ test("babel", function(t) { t.end() }) +test("should not be possible to use @action with getters", t => { + t.throws(() => { + class A { + @action get Test() { } + } + }, new Error('[mobx] action is not expected to be used with getters')) + + mobx.extras.resetGlobalState() + t.end() +}) + test("babel: parameterized computed decorator", t => { class TestClass { @observable x = 3 From a92e84146ca35e5d6d7c073d137a0deb6ebfaffd Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Wed, 23 Aug 2017 22:00:56 +0300 Subject: [PATCH 2/2] removed node_modules/mobx/lib/mobx.js.flow --- .flowconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/.flowconfig b/.flowconfig index 5488fc4dc..41afc31ab 100644 --- a/.flowconfig +++ b/.flowconfig @@ -6,7 +6,6 @@ test/flow [libs] flow-typed/ -node_modules/mobx/lib/mobx.js.flow [options] suppress_comment= \\(.\\|\n\\)*\\$ExpectError