You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RFC] Messaging RequestBody and ResponseBody type export #334
This feature atm is pretty hard lol I need a TS expert to go through it with
Basically, we need an expert at type inference and type generation. How can I infer MmMetadata["hash-tx"]["req"] to the sendToBackground call like this:
sendToBackground({name: "hash-tx",body: {}// <- this should have the type of MmMetadata["hash-tx"]["req"]})// This should return Promise<MmMetadata["hash-tx"]["res"]>
I was doing something vaguely similar in a different project. I'm completely new to Plasmo so this is probably not even what you're wanting.
This is just me typing out my thoughts. I want to reiterate I probably don't even understand the problem!
I think this will select the types based on the message name instead of just merging the request/response?
typeMmMetadata={"get-manifest": {}"hash-tx": {req: RequestBodyres: RequestResponse}"math/add": {}}typeRequestBody={a: stringb: number}typeRequestResponse={c: boolean}// Map over MmMetadata to create a new type with request and response types for each messagetypeMessageTypes={[KinkeyofMmMetadata]: MmMetadata[K]extends{req: infer R,res: infer S} ? {request: R,response: S} : never}// Now you can use a conditional type in sendToBackground to select the correct typesdeclarefunctionsendToBackground<TNameextendskeyofMessageTypes>(request: {name: TName,body: MessageTypes[TName]['request']}): Promise<MessageTypes[TName]['response']>;// Usage exampleletresult=sendToBackground({name: "hash-tx",body: {a: "string",b: 1}});// result is of type Promise<RequestResponse>
Activity
louisgv commentedon Apr 16, 2023
This feature atm is pretty hard lol I need a TS expert to go through it with
Basically, we need an expert at type inference and type generation. How can I infer
MmMetadata["hash-tx"]["req"]to the sendToBackground call like this:I'm basically stumped.
louisgv commentedon Apr 16, 2023
This is another attempt:
But it will not infer the exact ReqBody/ResBody pair given the name. It will just merge them all up. Is there a way to infer them???
louisgv commentedon Apr 17, 2023
Some other refs from tRPC for inspo:
dmwyatt commentedon Jun 16, 2023
I was doing something vaguely similar in a different project. I'm completely new to Plasmo so this is probably not even what you're wanting.
This is just me typing out my thoughts. I want to reiterate I probably don't even understand the problem!
I think this will select the types based on the message name instead of just merging the request/response?
Dan-RewardedInterest commentedon Dec 20, 2024
Hey team. Just wondering if there was any progress on this.
Happy to help if there is anything to be done.
Thanks for such an awesome project!!!