Add type support to react useAgent().call#269
Add type support to react useAgent().call#269threepointone merged 10 commits intocloudflare:mainfrom
Conversation
86d420f to
1c48719
Compare
🦋 Changeset detectedLatest commit: ac80e64 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
c18c9ec to
b0261ac
Compare
threepointone
left a comment
There was a problem hiding this comment.
this is great, thanks so much! a couple of questions
eaaa40b to
8bfea93
Compare
It was failing in windows with the following error: ``` Error: Failed to load url C:/worker.ts (resolved id: C:/worker.ts). Does the file exist? ❯ loadAndTransform ../../../../node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:35725:17 ```
c589a44 to
f8c76ee
Compare
|
I fixed some lint checks, and rebased on top of previous changes. There are a bunch of explicit anys, which I try to keep out of the codebase. If possible, could you replace them? If not possible, it's fine to skip the check with a You can run npm run check at the root to see whether it would pass checks btw |
|
I had to ignore those errors for now. Maybe in the future we can improve type checking for RPC and restrict types to the ones that are JSON compatible. |
|
there's still a type failure in rpc.tsx, which shows that it fails if you don't have an explicit type param passed, can we make it so that's still acceptable? a default <Agent, State> value? |
|
It seems that switching the order of overload functions fixes it. |
|
This is awesome, thanks for iterating on it. I'll do one final review and test it out tomorrow and land it. Great PR! |
Proposal to add type support to react useAgent() RPC calls. It can infer argument tyoes and ensure we pass all required values.
Usage example:
Intellisense in vscode:
Unfortunately, I didn't find a way to restrict calls to methods decorated with
@callable(), so it will also suggest non-RPC methods.Nevertheless, I excluded the ones declared in the base
Agentclass to ensure intellisense is as clean as possible.If there are public methods to exclude, it's always possible to exclude the non-RPC ones with
Omit<MyAgent, 'noRpc'>: