web-ext-types
web-ext-types copied to clipboard
StorageObject and custom Interface/Class
Hello! I am currently trying to cast a custom interface to a StorageObject to pass to the storage.local.set
method, however TS is saying this is not possible due to Index Signatures.
Line 928 indicates:
// The Index signature makes casting to/from classes or interfaces a pain. Custom types are OK.
Any tips for dealing with this? Thanks!
See PR #38 for details.
Types work fine. Classes and interfaces don't work well.
I know this isn't satisfactory. There are two solutions I can think of:
- Relax the type signatures so we get less false negatives at the cost of more false positives (objects which cannot be stored unaltered will no longer cause a compile time error)
- Make get and set generic and require users to give types if they want to use interfaces or classes
I don't know what's better, but I should probably change it.
Ah thank you for the extra info! I would personally lean towards option 2.