namespace Memento { interface State { } class Memento { private state : State ; constructor ( state ) { this . state = Object . assign ( { } as State , state ) ; } restore ( state ) { Object . assign ( state , this . state ) ; } } class Originator { state : State ; get memento ( ) : Memento { return new Memento ( this . state ) ; } set memento ( memento ) { memento . restore ( this . state ) ; } } class Caretaker { originator : Originator ; history : Memento [ ] = [ ] ; save ( ) { this . history . push ( this . originator . memento ) ; } restore ( ) { this . originator . memento = this . history . shift ( ) ; } } }