import { expectType } from 'tsd'; import type { Vow, VowTools } from '@agoric/vow'; 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>( castable as GuestOf, ); expectType<(p1: number, p2: number) => Vow>( castable as HostOf, ); expectType<(p1: number, p2: number) => Vow>( // @ts-expect-error incompatible return type castable as HostOf, ); // Test HostInterface and GuestInterface with an exoClass object type ExoAPIBase = { getValue: () => number; setValue: (value: number) => void; getCopyData: () => Record[]; // TODO include `getRemote() => Guarded<...>`, since durable exos are passable }; type ExoGuestAPI = ExoAPIBase & { getValueAsync: () => Promise; }; type ExoHostAPI = ExoAPIBase & { getValueAsync: () => Vow; }; expectType< ExoAPIBase & { getValueAsync: () => Vow; } >(castable as HostInterface); expectType< ExoAPIBase & { getValueAsync: () => Promise; } >(castable as GuestInterface); // Test HostInterface and GuestInterface with classKit (nested) objects expectType<{ facet: ExoAPIBase & { getValueAsync: () => Vow; }; }>( castable as HostInterface<{ facet: ExoGuestAPI; }>, ); expectType<{ facet: ExoAPIBase & { getValueAsync: () => Promise; }; }>( castable as GuestInterface<{ facet: ExoHostAPI; }>, );