Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to work with Json in TypeScript without as any #6352

Open
eladb opened this issue Apr 27, 2024 · 0 comments
Open

Impossible to work with Json in TypeScript without as any #6352

eladb opened this issue Apr 27, 2024 · 0 comments
Labels
✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl

Comments

@eladb
Copy link
Contributor

eladb commented Apr 27, 2024

Use Case

In our SDK TypeScript code and in Wing code written in TypeScript, every API that accepts/returns Json is awkward to use because it basically requires as any.

For example:

import { cloud, lift, main } from "@wingcloud/framework";

main((root, test) => {
  const b = new cloud.Bucket(root, "Bucket");

  const fn = new cloud.Function(
    root,
    "Function",
    lift({ b }).grant({ b: ["putJson"]}).inflight(async (ctx) => {
      await ctx.b.putJson("hello", "world");
//                                 ^^^^^^^ Argument of type 'string' is not assignable to parameter of type 'Json'.ts(2345)

      return undefined;
    })
  );
});

Proposed Solution

Not ideal but at least it will keep things within the framework and not escape the type system: perhaps we can offer some utility methods on the Json type to make it easy to construct:

Json.fromString("hello");
Json.fromNumber(123);
Json.fromObject({ df: 123 });

Json.toString(myJsonString)
// ...

Implementation Notes

No response

Component

No response

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.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@eladb eladb added ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl labels Apr 27, 2024
@eladb eladb changed the title Not fun to work with Json in TypeScript Impossible to work with Json in TypeScript without as any Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

1 participant