Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/mobx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# mobx

## 6.15.3

### Patch Changes

- [`25e859a3582bcdd3c5a71aa52510adfd924a1a60`](https://github.com/mobxjs/mobx/commit/25e859a3582bcdd3c5a71aa52510adfd924a1a60) [#4644](https://github.com/mobxjs/mobx/pull/4644) Thanks [@kubk](https://github.com/kubk)! - Fix TypeScript errors when using `flow` as a standard decorator.

## 6.15.2

### Patch Changes
Expand Down
56 changes: 56 additions & 0 deletions packages/mobx/__tests__/decorators_20223/stage3-decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,62 @@ test("it should support asyncAction as decorator (2022.3)", async () => {
expect(await x.f(3)).toBe(16)
})

test("it should support flow as decorator (2022.3)", async () => {
class DecoratorInferred {
@mobx.flow
*f() {
return true
}
}

class DecoratorExplicit {
@mobx.flow
*f(): Generator<never, boolean, unknown> {
return true
}
}

class AutoObservable {
constructor() {
mobx.makeAutoObservable(this)
}

*f() {
return true
}
}

class ExplicitObservable {
constructor() {
mobx.makeObservable(this, {
f: mobx.flow
})
}

*f() {
return true
}
}

class FlowField {
f = mobx.flow(function* () {
return true
})
}

const decoratorInferredResult: boolean = await mobx.flowResult(new DecoratorInferred().f())
const decoratorExplicitResult: boolean = await mobx.flowResult(new DecoratorExplicit().f())
const autoObservableResult: boolean = await mobx.flowResult(new AutoObservable().f())
const explicitObservableResult: boolean = await mobx.flowResult(new ExplicitObservable().f())
const flowFieldResult: boolean = await new FlowField().f()

expect(decoratorInferredResult).toBe(true)
expect(decoratorExplicitResult).toBe(true)
expect(autoObservableResult).toBe(true)
expect(explicitObservableResult).toBe(true)
expect(flowFieldResult).toBe(true)
})

test("toJS bug #1413 (2022.3)", () => {
class X {
@observable
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx",
"version": "6.15.2",
"version": "6.15.3",
"description": "Simple, scalable state management.",
"source": "src/mobx.ts",
"main": "dist/index.js",
Expand Down
9 changes: 8 additions & 1 deletion packages/mobx/src/api/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ export function isFlowCancellationError(error: Error) {

export type CancellablePromise<T> = Promise<T> & { cancel(): void }

interface Flow extends Annotation, PropertyDecorator, ClassMethodDecorator {
type FlowGenerator = (...args: any[]) => Generator<any, any, any> | AsyncGenerator<any, any, any>

// PropertyDecorator is only for legacy decorators
interface Flow extends Annotation, PropertyDecorator {
<This, Value extends FlowGenerator>(
value: Value,
context: ClassMethodDecoratorContext<This, Value>
): Value | void
<R, Args extends any[]>(
generator: (...args: Args) => Generator<any, R, any> | AsyncGenerator<any, R, any>
): (...args: Args) => CancellablePromise<R>
Expand Down
Loading