ts sdk: lifted resource types are off
Open
Nobody has claimed this yet.
🐛 bug
📜 typescript
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 215
- Avg merge
- 2h 9m
- Merged PRs (30d)
- 27
Description
I tried this:
Given these files:
import { cloud } from "@wingcloud/framework";
export const myServer = async ({bucket}: { bucket: cloud.IBucketClient }) => {
const file = await bucket.get("hello");
console.log(file);
return file;
}
import { cloud, lift, main } from "@wingcloud/framework";
import { myServer } from "./my-ssr-framework";
import assert from "node:assert";
main((root, test) => {
let bucket = new cloud.Bucket(root, "Bucket");
bucket.addObject("hello", "Hello World from lifted Bucket!");
new cloud.Function(root, "hello", lift({bucket}).inflight(async ({bucket}) => {
const result = await myServer({bucket})
return result;
}));
test("testing it works", lift({bucket}).inflight(async ({bucket}) => {
const result = await myServer({bucket})
assert.equal(result , "Hello World from lifted Bucket!");
}))
})
This happened:
a wing test main.ts fails with
11 const result = await myServer({bucket})
~~~~~~
my-ssr-framework.ts:3:44
3 export const myServer = async ({bucket}: { bucket: cloud.IBucketClient }) => {
~~~~~~
The expected type comes from property 'bucket' which is declared here on type '{ bucket: IBucketClient; }'
main.ts:16:36 - error TS2322: Type 'Bucket' is not assignable to type 'IBucketClient'.
16 const result = await myServer({bucket})
~~~~~~
my-ssr-framework.ts:3:44
3 export const myServer = async ({bucket}: { bucket: cloud.IBucketClient }) => {
~~~~~~
The expected type comes from property 'bucket' which is declared here on type '{ bucket: IBucketClient; }'
Tests 1 failed (1)
Test Files 1 failed (1)
Duration 0m0.79s
I expected this:
to work out the correct inflight types
Is there a workaround?
use cloud.Bucket type and cast via unknown to IBucketClient. It's only a type issue
Anything else?
No response
Wing Version
0.59.19
Node.js Version
v20.10.0
Platform(s)
MacOS
Community Notes
- Please vote by adding a 👍 reaction to the issue to help us prioritize.
- If you are interested to work on this issue, please leave a comment.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with wing test main.ts, using the types in my-ssr-framework.ts and the lift(...).inflight(...) calls in main.ts. Trace how the lifted Bucket is typed at those call sites; done means the example passes without casting through unknown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100