[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
This commit is contained in:
JulianWielga
2019-04-26 13:56:05 -07:00
committed by Pranav Senthilnathan
parent 3034a2763c
commit a3b8548fb3
3 changed files with 20 additions and 1 deletions
+2 -1
View File
@@ -45,7 +45,8 @@ export interface TaskStatusAware<Result = any, Args extends any[] = any[]> exten
export interface TaskCreator<K extends keyof TaskOptions<any>> extends MethodDecorator, PropertyDecorator {
<R, A extends any[]>(func: TaskFunc<R, A>, options?: Pick<TaskOptions<WithoutPromise<R>>, K>): TaskStatusAware<WithoutPromise<R>, A>;
(options: Pick<TaskOptions<WithoutPromise<any>>, K>): PropertyDecorator | MethodDecorator;
(options: Pick<TaskOptions<WithoutPromise<any>>, K>): PropertyDecorator;
(options: Pick<TaskOptions<WithoutPromise<any>>, K>): MethodDecorator;
}
export interface TaskFactory extends TaskCreator<keyof TaskOptions<any>> {
+17
View File
@@ -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() {}
}
+1
View File
@@ -8,6 +8,7 @@
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"experimentalDecorators": true,
"baseUrl": "../",
"typeRoots": [
"../"