web-ext-types icon indicating copy to clipboard operation
web-ext-types copied to clipboard

StorageObject and custom Interface/Class

Open nokeeo opened this issue 7 years ago • 2 comments

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!

nokeeo avatar Dec 19 '17 13:12 nokeeo

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:

  1. 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)
  2. 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.

cmcaine avatar Jan 06 '18 13:01 cmcaine

Ah thank you for the extra info! I would personally lean towards option 2.

nokeeo avatar Jan 06 '18 18:01 nokeeo