Would not recommend to use the localStorage object like that in Typescript or plain Javascript. How can you be sure you want all the items stored on localstorage or that they will be JSON parsable? It's better to keep a list of localstorage keys for your app somewhere and loop through that, instead of all the keys on the localstorage object.
constcacheKeys=['cache_item_one','cache_item_two','etc...']cacheKeys.forEach(key=>{constvalue=localStorage.getItem(key)if(value){try{store.commit('cache/init',{key,value:JSON.parse(value)})}catch(e){// wrap JSON.parse in a try catch block to avoid unexpected crashes}}})
Your code duplication issue I'm not too familiar with Nuxt. Do they have Typescript documentation? If so, they'll usually explain how you're supposed to extend the built in interfaces.
No idea what you're trying to do with that URLBuilder =P
I don't think there's a hype around Typescript, but it is slowly growing because people appreciate type safety (or they learn to) and not having as many runtime errors.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nothing wrong with learning.
Would not recommend to use the localStorage object like that in Typescript or plain Javascript. How can you be sure you want all the items stored on localstorage or that they will be JSON parsable? It's better to keep a list of localstorage keys for your app somewhere and loop through that, instead of all the keys on the localstorage object.
For your string literals, try this:
Your code duplication issue I'm not too familiar with Nuxt. Do they have Typescript documentation? If so, they'll usually explain how you're supposed to extend the built in interfaces.
No idea what you're trying to do with that URLBuilder =P
I don't think there's a hype around Typescript, but it is slowly growing because people appreciate type safety (or they learn to) and not having as many runtime errors.