Skip to content

Support nested object graph access in Remote types#697

Open
KirtiRamchandani wants to merge 1 commit into
GoogleChromeLabs:mainfrom
KirtiRamchandani:fix/remote-object-graph-types
Open

Support nested object graph access in Remote types#697
KirtiRamchandani wants to merge 1 commit into
GoogleChromeLabs:mainfrom
KirtiRamchandani:fix/remote-object-graph-types

Conversation

@KirtiRamchandani

Copy link
Copy Markdown

Fixes #680.

Problem

RemoteProperty<T> currently types unmarked object properties only as Promise<T>. At runtime, those properties can also be traversed as remote proxy paths, so proxy.service.method() works but TypeScript rejects it.

Root cause

The conditional type collapses every non-function, non-ProxyMarked property to Promisify<T>, which loses the nested remote object surface.

Solution

For object properties, expose an intersection of Remote<T> and Promise<T>. This keeps await proxy.service typed as the cloned object while also typing proxy.service.method() and other nested proxy-path access.

Tests

  • npm run test:types
  • npm run build
  • npm run test:node
  • npx prettier --check src/comlink.ts tests/type-checks.ts
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript typings seem off when wrapping an object graph

1 participant