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

Typed HyperDurable class methods? #29

Open
mpint opened this issue Jun 11, 2023 · 3 comments
Open

Typed HyperDurable class methods? #29

mpint opened this issue Jun 11, 2023 · 3 comments

Comments

@mpint
Copy link

mpint commented Jun 11, 2023

Hello, I've been playing around with the library and really enjoying it, but can't figure out how to make HyperDurable class methods type safe. Is there a way to get a strongly typed stub?

Screen Shot 2023-06-11 at 9 47 42 AM
@travismfrank
Copy link
Contributor

Hi @mpint! 👋 This should work by default, looks like something is up with the type definitions. I'm working off a modified fork where I fixed this, I need to merge my changes.

In the meantime, a quick and dirty fix is to cast the namespace proxy with HyperNamespaceProxy:

import { HyperNamespaceProxy, proxyHyperDurables } from '@ticketbridge/hyper-durable';

// Proxy the namespace
const proxied = proxyHyperDurables(env, {
  // BINDINGNAME: DurableObjectClass
  RUBBERDUCK: RubberDuck
});
const RUBBERDUCK = proxied.RUBBERDUCK as HyperNamespaceProxy<RubberDuck, Env>;

Please let me know if you run into any other issues. :)

@mpint
Copy link
Author

mpint commented Jun 12, 2023

No worries. The issue might be on my end. Just to elaborate a bit more, RubberDuck looks like this. Anything I'm missing in the definition?

type DuckData = {
  name: string
  favoriteFoods: string[]
}

export class RubberDuck extends HyperDurable<DuckData, Bindings> { ... }

@mpint
Copy link
Author

mpint commented Jul 16, 2023

Hi, just circling back on this and still dealing with missing method types in a stub instance. Any chance you could merge in those updated type definitions you mentioned earlier? My tests for RubberDuck are passing so I'm certain its wired up correctly.

Screenshot 2023-07-16 at 9 36 48 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants