I have a variable
of type Storage
- this is what variable.constructor.name
says. How can I now determine is it localStorage
or sessionStorage
? I just need the name.
Example code:
class WebStorage {
constructor(public storage: Storage) {}
public getStorageName(): 'LocalStorage' | 'SessionStorage' {
// how to return proper name?
}
}
I believe you can simply compare it:
return storage === window.localStorage ? 'LocalStorage' : 'SessionStorage';