Skip to content

TypeScript: Parse.Cloud.onLiveQueryEvent is still missing from the shipped type definitions #10601

Description

@MrEkinox

New Issue Checklist

  • I am not disclosing a security vulnerability.
  • I have searched through existing issues.
  • I am using a recent Parse Server version.
  • I have included a minimal reproduction.

Issue Description

Parse.Cloud.onLiveQueryEvent exists at runtime, is implemented by Parse Server, and is documented in the official Cloud Code guide, but it is missing from the TypeScript definitions exposed through Parse.Cloud.

This issue was previously reported in #9282, but it was closed as a question and the runtime / type definition mismatch still exists in Parse Server 9.10.0.

Official documentation:

https://docs.parseplatform.org/cloudcode/guide/#onlivequeryevent

The runtime implementation is present in Parse Server:

ParseCloud.onLiveQueryEvent = function (handler) {
  triggers.addLiveQueryEventHandler(handler, Parse.applicationId);
};

However, TypeScript resolves Parse.Cloud from the parse package's Cloud definitions, where onLiveQueryEvent is not declared.

Steps to Reproduce

Create a TypeScript Cloud Code file:

import Parse from 'parse/node.js';

Parse.Cloud.onLiveQueryEvent(async request => {
  console.log(request.event);
});

Run TypeScript:

tsc --noEmit

Actual Outcome

TypeScript reports:

Property 'onLiveQueryEvent' does not exist on type
'typeof import("node_modules/parse/types/Cloud")'. ts(2339)

The method nevertheless exists and works at runtime.

Expected Outcome

Parse.Cloud.onLiveQueryEvent should be included in the TypeScript definitions available to Parse Server Cloud Code.

The callback should also expose the documented event properties, including:

type LiveQueryEvent =
  | 'connect'
  | 'subscribe'
  | 'unsubscribe'
  | 'ws_connect'
  | 'ws_disconnect'
  | 'ws_disconnect_error';

interface LiveQueryEventRequest {
  event: LiveQueryEvent;
  client?: unknown;
  user?: Parse.User;
  sessionToken?: string;
  installationId?: string;
  useMasterKey: boolean;
  clients: number;
  subscriptions: number;
  error?: unknown;
}

For example:

namespace Parse.Cloud {
  function onLiveQueryEvent(
    handler: (
      request: LiveQueryEventRequest
    ) => void | Promise<void>
  ): void;
}

The precise location of this declaration may need to be discussed because Parse.Cloud comes from the parse package while the method is injected by parse-server.

Parse Server could potentially:

  1. ship a TypeScript module augmentation for the Parse SDK;
  2. expose dedicated Cloud Code types;
  3. or coordinate the declaration with the Parse JavaScript SDK repository.

If this type must be added to the Parse JavaScript SDK instead, please transfer or redirect the issue rather than closing it as a usage question, since the documented Parse Server API currently has no official TypeScript representation.

Workaround

The only reliable workaround currently is a manual type assertion:

type OnLiveQueryEvent = (
  handler: (
    request: LiveQueryEventRequest
  ) => void | Promise<void>
) => void;

const cloud = Parse.Cloud as typeof Parse.Cloud & {
  onLiveQueryEvent: OnLiveQueryEvent;
};

cloud.onLiveQueryEvent(async request => {
  console.log(request.event);
});

Attempts to augment internal modules are unreliable:

declare module 'parse/types/Cloud' {
  // ...
}

This fails because the internal module is not publicly resolvable:

Invalid module name in augmentation.
Module 'parse/types/Cloud' cannot be found.

Augmenting parse, parse/node, or parse/node.js also does not reliably merge into the separately imported and re-exported Cloud namespace.

Environment

  • Parse Server version: 9.10.0
  • Parse JavaScript SDK version: 8.6.0
  • TypeScript version: 7.0.2
  • Node.js version: 24.18.0
  • Operating system: macOS
  • Database: MongoDB

Additional Context

Other Parse Server-only Cloud Code APIs may be affected by the same architectural issue because the Parse.Cloud runtime object is extended by Parse Server while its base TypeScript declarations are owned by the Parse JavaScript SDK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions