serversideup / webext-bridge

💬 Messaging in Web Extensions made easy. Batteries included.
https://serversideup.net/open-source/webext-bridge
MIT License
553 stars 50 forks source link

[Bug] `DataTypeKey` not working on `onMessage` and `sendMessage` parameter `messageID` #60

Closed ziloen closed 1 year ago

ziloen commented 1 year ago

Screenshot

zikaari commented 1 year ago

I'm not understanding your issue, please describe with an example

ziloen commented 1 year ago

https://github.com/zikaari/webext-bridge/blob/320d2501599ed4e261801b0b65823b953633788a/src/internal/endpoint-runtime.ts#L16-L34

In the source code, messageID has a generic type DataTypeKey, but in the user's actual type file, the generic type of messageID changes to string, and when I expand the ProtocolMap type, I don't get a type hint at the messageID

// modules.d.ts
declare module "webext-bridge" {
  export interface ProtocolMap {
    foo: { title: string }
    bar: ProtocolWithReturn<CustomDataType, CustomReturnType>;
  }
}

// background.ts
onMessage(messageID, ...)
//        ^ no type hint and accept any string
ziloen commented 1 year ago

Looks the same as #51, feel free to close.