open-wc / context-protocol

A Lit compatible implementation of the context-protocol community protocol
8 stars 1 forks source link

missing type definitions for some class members #26

Open trusktr opened 1 month ago

trusktr commented 1 month ago

Looks like the type defs might need an update (willing to help if I can circle back time willing). F.e. this.contexts is available, but this.getContext() is not:

Screenshot 2024-08-03 at 1 34 58 PM Screenshot 2024-08-03 at 1 35 04 PM
trusktr commented 1 month ago

Ah, its because the mixin uses ConsumerElement to cast the return type, which misses out on any type in the mixin class definition.

https://github.com/open-wc/context-protocol/blob/e7ab38195b7fb0315faccbeb74575d381eec437d/index.ts#L34-L36

This can be fixed by allowing the return value to be the actual type returned. Instead of returning the ConsumerElement definition, it can be merged into the base Class type, then everything in the mixin class will propagate through the return value including ConsumerElement.

Alternatively, we can write duplicate types in the ConsumerElement type, but it can be error prone if the mixin class is changed but ConsumerElement isn't.