antfu-collective / vitesse-webext

⚡️ WebExtension Vite Starter Template
MIT License
2.9k stars 224 forks source link

typing for storageInterface.getItem #193

Closed uinstinct closed 1 month ago

uinstinct commented 1 month ago

Description

The inferred type of storedData[key] in the changed line is inferred as unknown but the StorageLikeAsync expects type as string.

Linked Issues

Additional context

tmkx commented 1 month ago

storage.local.get can return any JSON serializable object, maybe

return data == null
  ? null
  : typeof data === 'string'
    ? data
    : JSON.stringify(data)

is more robust?

uinstinct commented 1 month ago

storage.local.get can return any JSON serializable object, maybe

return data == null
  ? null
  : typeof data === 'string'
    ? data
    : JSON.stringify(data)

is more robust?

setItem has a type of string on value argument. Hence, we can safely type it as string

tmkx commented 1 month ago

yes, but the storage can be manipulated by other dependencies. it seems a little over-engineered as a template project. let's get it merged!