function get < T extends any > ( key , defaultValue ) ; function get < T extends any > ( key ) ; function get < T extends any > ( key , defaultValue ? ) { try { const item = localStorage . getItem ( key ) ; if ( item ) { return JSON . parse ( item ) ; } else { return defaultValue ; } } catch ( err ) { return defaultValue ; } } function set ( key , value ) { localStorage . setItem ( key , JSON . stringify ( value ) ) ; } export interface SharedState { theme : string ; vimModeEnabled : boolean ; showPreferences : boolean ; } const state = { theme : 'dark-grad' , vimModeEnabled : false , showPreferences : false , } ; export default { state , load ( ) { state . theme = get < string > ( 'theme' , state . theme ) ; state . vimModeEnabled = get < boolean > ( 'vimModeEnabled' , state . vimModeEnabled ) ; } , commit < K extends keyof SharedState > ( key , value , persist = false ) { if ( persist ) { set ( key , value ) ; } state [ key ] = value ; } , } ;