Skip to content

Commit

Permalink
Added World generic type to Action and PromiseAction
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Nov 12, 2021
1 parent c8f8ad5 commit 143d4a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Added `World` generic type to `Action` and `PromiseAction`

### Changed

### Deprecated
Expand Down
8 changes: 4 additions & 4 deletions src/Actor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type Action<Answer = void> = (actor: Actor) => Answer
export type PromiseAction<Answer = void> = (actor: Actor) => Promise<Answer>
export type Action<Answer = void, World = unknown> = (actor: Actor<World>) => Answer
export type PromiseAction<Answer = void, World = unknown> = (actor: Actor<World>) => Promise<Answer>

export type DefaultFunction<T> = () => T

Expand All @@ -21,14 +21,14 @@ export default class Actor<World = unknown> {
return this.memory.get(key) as T
}

public attemptsTo<Answer>(action: Action<Answer>): Answer {
public attemptsTo<Answer>(action: Action<Answer, World>): Answer {
return action(this)
}

/**
* Just a synonym for attemptsTo
*/
public ask<Answer>(action: Action<Answer>): Answer {
public ask<Answer>(action: Action<Answer, World>): Answer {
return action(this)
}
}

0 comments on commit 143d4a2

Please sign in to comment.