eonarheim / TypeState

A strongly typed finite state machine for TypeScript
http://eonarheim.github.io/TypeState/example/
BSD 2-Clause "Simplified" License
272 stars 29 forks source link

Wrong ts type for callbacks in onEnter/onExit/onInvalidTransition #38

Closed AndersCan closed 4 years ago

AndersCan commented 4 years ago

onEnter (and other functions with callbacks) look like this:

public onEnter(state: T, callback: (from?: T, event?: any) => ... {...}

From reading the code, I think it should be: callback: (from: T, event?: any) as callback is always called with either state or this.currentState. If the ? is correct I think the docs should mention this :)

Made a playground showing the issue.

Let me know if I should make a PR with these changes :)

eonarheim commented 4 years ago

Hi @AndersCan thanks for the issue!

You are right, the from argument should always be populated on transition.

Definitely would accept a PR to this effect :+1: