diff --git a/packages/eventual-send/src/index.d.ts b/packages/eventual-send/src/index.d.ts index 0b3064e267..7c75759f6c 100644 --- a/packages/eventual-send/src/index.d.ts +++ b/packages/eventual-send/src/index.d.ts @@ -234,7 +234,10 @@ interface EProxy { * @param x target for method/function call * @returns method/function call proxy */ - (x: T): ECallableOrMethods>; + // (x: NonNullable): ECallableOrMethods>; + // (undefined): Record; + // (x: null): Record; + (x: NonNullable): ECallableOrMethods>; /** * E.get(x) returns a proxy on which you can get arbitrary properties. diff --git a/packages/eventual-send/src/index.test-d.ts b/packages/eventual-send/src/index.test-d.ts index 74aca3b523..84353f33b7 100644 --- a/packages/eventual-send/src/index.test-d.ts +++ b/packages/eventual-send/src/index.test-d.ts @@ -1,5 +1,6 @@ /* eslint-disable @endo/no-polymorphic-call, import/no-extraneous-dependencies, no-restricted-globals, prettier/prettier */ import { expectType } from 'tsd'; +import { Far } from '@endo/marshal'; import { E } from '../test/get-hp.js'; import { DataOnly, ERef } from './index.js'; @@ -46,3 +47,47 @@ const foo2 = async (a: FarRef<{ bar(): string; baz: number }>) => { // @ts-expect-error - calling directly is valid but not yet in the typedef a.bar; }; + +// Nullish handling +type SomeRemotable = { someMethod: () => 'hello'; someVal: 'alsoHello' }; +const undefinedCase = () => { + let ref: SomeRemotable | undefined; + // @ts-expect-error can't proxy an undefined value + E(ref); + // @ts-expect-error could be undefined + E(ref).someMethod(); + // @ts-expect-error optional chaining doesn't work with E() + E(ref)?.someMethod(); + // @ts-expect-error could be undefined + E.get(ref); + const getters = E.get(ref); + expectType < EGetters(getters); + getters.someMethod.then(sayHello => sayHello()); + getters.someVal; +}; +const promiseUndefinedCase = () => { + let ref: Promise; + // @ts-expect-error can't proxy an undefined value + E(ref); + // @ts-expect-error could be undefined + E(ref).someMethod(); + // @ts-expect-error optional chaining doesn't work with E() + E(ref)?.someMethod(); + // @ts-expect-error could be undefined + E.get(ref); + const getters = E.get(ref); + getters.someMethod.then(sayHello => sayHello()); + getters.someVal; +}; +const nullCase = () => { + let ref: SomeRemotable | null; + // @ts-expect-error could be null + E(ref).someMethod(); + // @ts-expect-error optional chaining doesn't work with E() + E(ref)?.someMethod(); + // @ts-expect-error could be null + E.get(ref); + const getters = E.get(ref!); + getters.someMethod.then(sayHello => sayHello()); + getters.someVal; +};