parse-community / parse-community/parse-server
TypeScript: Parse.Cloud.onLiveQueryEvent is still missing from the shipped type definitions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
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:
- ship a TypeScript module augmentation for the Parse SDK;
- expose dedicated Cloud Code types;
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Parse package's Cloud type definitions and the Parse Server runtime implementation of ParseCloud.onLiveQueryEvent. Reproduce the mismatch with the TypeScript example and tsc --noEmit, then determine whether the declaration belongs in Parse Server or the Parse JavaScript SDK. Done means the documented API and callback properties are officially typed and the example type-checks without assertions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, typescript
- Domain
- backend-api-design, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100