From a3b8548fb324da5c43fc979eb30a7a7cb7815e52 Mon Sep 17 00:00:00 2001 From: JulianWielga Date: Fri, 26 Apr 2019 22:56:05 +0200 Subject: [PATCH] [mobx-task] Fixed property decorator definition (#34851) * [mobx-task] Fixed property decorator definition * Revert "[mobx-task] Fixed property decorator definition" This reverts commit 20bd533e * test for decorators & last change * [mobx-task] Fixed property decorator definition --- types/mobx-task/index.d.ts | 3 ++- types/mobx-task/mobx-task-tests.ts | 17 +++++++++++++++++ types/mobx-task/tsconfig.json | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/types/mobx-task/index.d.ts b/types/mobx-task/index.d.ts index 90be27e931..85df15ec54 100644 --- a/types/mobx-task/index.d.ts +++ b/types/mobx-task/index.d.ts @@ -45,7 +45,8 @@ export interface TaskStatusAware exten export interface TaskCreator> extends MethodDecorator, PropertyDecorator { (func: TaskFunc, options?: Pick>, K>): TaskStatusAware, A>; - (options: Pick>, K>): PropertyDecorator | MethodDecorator; + (options: Pick>, K>): PropertyDecorator; + (options: Pick>, K>): MethodDecorator; } export interface TaskFactory extends TaskCreator> { diff --git a/types/mobx-task/mobx-task-tests.ts b/types/mobx-task/mobx-task-tests.ts index 8f27a141e4..92e0d3a7d1 100644 --- a/types/mobx-task/mobx-task-tests.ts +++ b/types/mobx-task/mobx-task-tests.ts @@ -23,6 +23,13 @@ task1.match({ rejected: error => error.message, }); +// $ExpectType string | number +task1.match({ + resolved: res => 1, + pending: (txt, num) => txt, + rejected: error => error.message, +}); + // wrap const task2 = task(func); const task2ToString = task2.wrap(inner => { @@ -36,3 +43,13 @@ task2ToString.result; // $ExpectType string | undefined const task3 = task(func, { result: 1, state: 'resolved' }); task3.setState({ result: 2, state: 'pending' }); task3.setState({ result: '2', state: 'pending' }); // $ExpectError + +class TestClass { + @task fieldWithArrowFn = () => {}; + @task({ swallow: true }) fieldWithArrowFn2 = () => {}; + fieldWithArrowFn3 = task(() => {}, { swallow: true }); + + @task method() {} + + @task({ swallow: true }) method2() {} +} diff --git a/types/mobx-task/tsconfig.json b/types/mobx-task/tsconfig.json index dd74ced6ba..dc8124044e 100644 --- a/types/mobx-task/tsconfig.json +++ b/types/mobx-task/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, + "experimentalDecorators": true, "baseUrl": "../", "typeRoots": [ "../"