export interface History { undo: () => History | undefined; redo: () => History | undefined; get: () => T; add: (value: T) => History; } export class HistoryImpl implements History { private readonly item: T; private previous?: History; private next?: History; constructor(item: T) { this.item = item; } public get(): T { return this.item; } public undo(): History | undefined { return this.previous; } public redo(): History | undefined { return this.next; } public add(value: T): History { const newHistory = new HistoryImpl(value); newHistory.previous = this; this.next = newHistory; return newHistory; } }