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

way to define an object type from its interface guard #9163

Open
turadg opened this issue Mar 28, 2024 · 0 comments
Open

way to define an object type from its interface guard #9163

turadg opened this issue Mar 28, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@turadg
Copy link
Member

turadg commented Mar 28, 2024

What is the Problem Being Solved?

Consider,

/**
 * @typedef {object} App
 * @property {(obj: any) => Promise<unknown>} upcall return value depends on the
 *   bridge semantics
 */
export const AppI = M.interface('App', {
  upcall: M.call(M.any()).returns(M.promise()),
});

// contrived
/** @typedef {(target: string, app: ERef<App>) => Promise<TargetUnregister>} registerApp */

The guards define the interface, but:

  1. lose some useful type data
  2. define a guard object versus a usable one

So a type has to be specified for App, but AppI doesn't get an annotation so:

  1. the typedef appears to be an annotation when it isn't
  2. the names are repeated

Description of the Design

#6160 is to solve this generally but a stop-gap could be:

/**
 * @typedef {object} App
 * @property {(obj: any) => Promise<unknown>} upcall return value depends on the
 *   bridge semantics
 */
/** @type {GuardInterface<App>} */
export const AppI = M.interface('App', {
  upcall: M.call(M.any()).returns(M.promise()),
});

See also,

Security Considerations

Scaling Considerations

Test Plan

Upgrade Considerations

@turadg turadg added the enhancement New feature or request label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant