winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.94k stars 194 forks source link

ts sdk: lifted resource types are off #5809

Open skorfmann opened 6 months ago

skorfmann commented 6 months ago

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

github-actions[bot] commented 3 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 2 weeks ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!