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

fix: typedef of E() proxy parameter constraint #1224

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/eventual-send/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ interface EProxy {
* @param x target for method/function call
* @returns method/function call proxy
*/
<T>(x: T): ECallableOrMethods<RemoteFunctions<T>>;
// <T>(x: NonNullable<T>): ECallableOrMethods<RemoteFunctions<T>>;
// (undefined): Record<PropertyKey, never>;
// (x: null): Record<PropertyKey, never>;
<T>(x: NonNullable<T>): ECallableOrMethods<RemoteFunctions<T>>;

/**
* E.get(x) returns a proxy on which you can get arbitrary properties.
Expand Down
45 changes: 45 additions & 0 deletions packages/eventual-send/src/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<SomeRemotable | undefined>(getters);
getters.someMethod.then(sayHello => sayHello());
getters.someVal;
};
const promiseUndefinedCase = () => {
let ref: Promise<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);
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;
};