-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: GuestInterface supports synchronous returns
- Loading branch information
1 parent
b36bb55
commit 0ac0e68
Showing
3 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,73 @@ | ||
import { expectType } from 'tsd'; | ||
import type { Zone } from '@agoric/base-zone'; | ||
import type { Vow, VowTools } from '@agoric/vow'; | ||
import type { HostOf, GuestOf } from '../src/types.js'; | ||
import type { | ||
HostOf, | ||
GuestOf, | ||
HostInterface, | ||
GuestInterface, | ||
} from '../src/types.js'; | ||
|
||
const castable: unknown = null; | ||
const vt: VowTools = null as any; | ||
|
||
const sumVow = (a: number, b: number) => vt.asVow(() => a + b); | ||
|
||
const sumPromise = (a: number, b: number) => Promise.resolve(a + b); | ||
|
||
expectType<(p1: number, p2: number) => Promise<number>>( | ||
null as unknown as GuestOf<typeof sumVow>, | ||
castable as GuestOf<typeof sumVow>, | ||
); | ||
|
||
expectType<(p1: number, p2: number) => Vow<number>>( | ||
null as unknown as HostOf<typeof sumPromise>, | ||
castable as HostOf<typeof sumPromise>, | ||
); | ||
expectType<(p1: number, p2: number) => Vow<void>>( | ||
// @ts-expect-error incompatible return type | ||
null as unknown as HostOf<typeof sumPromise>, | ||
castable as HostOf<typeof sumPromise>, | ||
); | ||
|
||
// Test HostInterface and GuestInterface with an exoClass object | ||
type ExoAPIBase = { | ||
getValue: () => number; | ||
setValue: (value: number) => void; | ||
getCopyData: () => Record<string, number>[]; | ||
// TODO include `getRemote() => Guarded<...>`, since durable exos are passable | ||
}; | ||
type ExoGuestAPI = ExoAPIBase & { | ||
getValueAsync: () => Promise<number>; | ||
}; | ||
|
||
type ExoHostAPI = ExoAPIBase & { | ||
getValueAsync: () => Vow<number>; | ||
}; | ||
|
||
expectType< | ||
ExoAPIBase & { | ||
getValueAsync: () => Vow<number>; | ||
} | ||
>(castable as HostInterface<ExoGuestAPI>); | ||
expectType< | ||
ExoAPIBase & { | ||
getValueAsync: () => Promise<number>; | ||
} | ||
>(castable as GuestInterface<ExoHostAPI>); | ||
|
||
// Test HostInterface and GuestInterface with classKit (nested) objects | ||
expectType<{ | ||
facet: ExoAPIBase & { | ||
getValueAsync: () => Vow<number>; | ||
}; | ||
}>( | ||
castable as HostInterface<{ | ||
facet: ExoGuestAPI; | ||
}>, | ||
); | ||
expectType<{ | ||
facet: ExoAPIBase & { | ||
getValueAsync: () => Promise<number>; | ||
}; | ||
}>( | ||
castable as GuestInterface<{ | ||
facet: ExoHostAPI; | ||
}>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters