Created
July 31, 2018 18:16
-
-
Save mattiamanzati/335e18bf58001b444a6831b000589e4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | |
type Override<T, K extends keyof T, V> = Omit<T, K> & { [N in K]: V } | |
type AnyStateConfig = { | |
type: "initial" | "state" | "final" | |
states: {[K: string]: AnyStateConfig} | |
} | |
type EmptyStateConfig = { | |
type: "state" | |
states: {} | |
} | |
class State<C extends AnyStateConfig = EmptyStateConfig>{ | |
constructor( | |
public readonly config: C | |
){ | |
} | |
type<StateType extends AnyStateConfig["type"]>(type: StateType): State<Override<C, "type", StateType>>{ | |
return new State({ ...(this.config as any), type}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment