Skip to content

Commit

Permalink
types: Refine types on HyperStub
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Frank committed Jun 14, 2022
1 parent 4a93f00 commit e4a6a7d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ticketbridge/hyper-durable",
"version": "0.1.11",
"version": "0.1.12",
"description": "Object-like access to Durable Object properties and methods",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions src/HyperNamespaceProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export class HyperNamespaceProxy<DO extends HyperDurable<any, ENV>, ENV> impleme
// fetch interface.
type PromisedGetStub = {
[Prop in keyof DO]?:
DO[Prop] extends Function
? () => Promise<unknown>
: Promise<unknown>;
DO[Prop] extends (...args: any) => any
? (...args: Parameters<DO[Prop]>) => Promise<ReturnType<DO[Prop]>>
: Promise<DO[Prop]>;
};
// All of our props have setters formatted as: setProperty()
type SetStub = {
[Prop in keyof DO as DO[Prop] extends Function ? never : `set${Capitalize<string & Prop>}`]?:
(newValue: DO[Prop]) => Promise<unknown>
(newValue: DO[Prop]) => Promise<DO[Prop]>
}
type HyperStub = DurableObjectStub & PromisedGetStub & SetStub;

Expand Down
8 changes: 4 additions & 4 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export class HyperNamespaceProxy<DO extends HyperDurable<any, Env>, Env> {
);
get(id: DurableObjectId): DurableObjectStub & {
[Prop in keyof DO]:
DO[Prop] extends Function
? () => Promise<unknown>
: Promise<unknown>;
DO[Prop] extends (...args: any) => any
? (...args: Parameters<DO[Prop]>) => Promise<ReturnType<DO[Prop]>>
: Promise<DO[Prop]>;
} & {
[Prop in keyof DO as DO[Prop] extends Function ? never : `set${Capitalize<string & Prop>}`]:
(newValue: DO[Prop]) => Promise<unknown>
(newValue: DO[Prop]) => Promise<DO[Prop]>
};
}

Expand Down

0 comments on commit e4a6a7d

Please sign in to comment.