eonarheim / TypeState

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

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

Closed AndersCan closed 3 years ago

AndersCan commented 3 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 3 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: