fix: Cloud trigger type errors for void returns and subclass constructors - #2904
Conversation
…l constructor params
…iour with prior DefinitelyTyped code)
|
🚀 Thanks for opening this pull request! |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
📝 WalkthroughWalkthroughIntroduce a generic type alias ParseObjectConstructor and replace inline constructor signatures across Cloud Code APIs; widen many hook handler return types to allow synchronous void/undefined in addition to Promise/value returns. Update JSDoc and declaration files to match the new types. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #2904 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 6235 6235
Branches 1481 1477 -4
=========================================
Hits 6235 6235 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/CloudCode.ts`:
- Around line 286-290: Add a file-level ESLint disable for the void-in-union
rule to src/CloudCode.ts so the numerous trigger declarations (e.g.,
beforeSave<T extends ParseObject = ParseObject>, and the other handler
signatures) can legally use void in their union return types; specifically,
insert a top-of-file comment disabling `@typescript-eslint/no-invalid-void-type`
(e.g., a file-level eslint-disable for that rule) before any imports or code so
all handler declarations in this file are exempt.
|
It seems the current TS ESLint doesn't like it when we do union to |
|
Is this OK for merge? |
|
@coderabbitai suggest a PR title (changelog entry) for this PR. |
|
Tip For best results, initiate chat on the files or code changes.
Option 1 (Concise): Option 2 (More descriptive): Option 3 (Detailed): Option 4 (User-focused): I'd recommend Option 1 or Option 2 as they strike a good balance between being concise for a changelog while clearly communicating both fixes: the void return type support and the ability to use ParseObject subclasses with required constructor arguments. |
|
@coderabbitai For a fix, it should describe the issue, not the solution |
|
Tip For best results, initiate chat on the files or code changes.
Option 1 (Concise): Option 2 (Both issues): Option 3 (More specific): Option 4 (Regression-focused): Option 5 (Dual issue): I'd recommend Option 1 for clarity and brevity, or Option 2 if you want to acknowledge both issues addressed in this PR. |
## [8.1.1-alpha.3](8.1.1-alpha.2...8.1.1-alpha.3) (2026-02-07) ### Bug Fixes * Cloud trigger type errors for void returns and subclass constructors ([#2904](#2904)) ([de9f56d](de9f56d))
|
🎉 This change has been released in version 8.1.1-alpha.3 |
# [8.2.0](8.1.0...8.2.0) (2026-02-20) ### Bug Fixes * `Parse.Object.createWithoutData` doesn't preserve object subclass ([#2907](#2907)) ([01dc94d](01dc94d)) * `Parse.Query.and/or/nor` loosing custom class types ([#2903](#2903)) ([89fdb07](89fdb07)) * `Parse.serverURL` not accessible via global `Parse` scope ([#2917](#2917)) ([4e78681](4e78681)) * Cloud trigger type errors for void returns and subclass constructors ([#2904](#2904)) ([de9f56d](de9f56d)) * Missing or incorrect type exports ([#2909](#2909)) ([3caa4ec](3caa4ec)) * Type error in `Parse.Query.equalTo` when matching optional array ([#2901](#2901)) ([8c96da9](8c96da9)) ### Features * Add request header `X-Parse-Upload-Mode` to identify file upload as binary data via `Buffer`, `Readable`, `ReadableStream` ([#2927](#2927)) ([a66bb06](a66bb06)) * Add support for file upload as binary data via `Buffer`, `Readable`, `ReadableStream` ([#2925](#2925)) ([e42caf6](e42caf6))
|
🎉 This change has been released in version 8.2.0 |
Pull Request
Issue
This both fixes a regression in cloud trigger return typings & fixes a longstanding issue when defining triggers on subclasses.
The current typings allow only for triggers to return something e.g. undefined, or the exact object class (which is generally likely the same request.object).
However, the behaviour commonly used, and was accepted in the prior DefinitelyTyped-defined typings, was to simply not return anything and do mutations on the object e.g.
request.object.set(...), which would mean a function with a return type ofvoid. Since the typings do not allow forvoidreturns, upgrading a prior codebase to a newer version of Parse JS SDK with built-in typings will cause errors.Another thing that this fixes is for subclasses of Parse.Object that have non-optional arguments for types,
Parse.Cloudtriggers (e.g.Parse.Cloud.beforeSave) previously was typed using thenew () => Tsyntax, which means anything with constructor arguments could not be typed. This now allows for us to do things like.Approach
Added
voidreturn type to Parse.Cloud typings.Fixed type trigger class generic typings to allow for subclasses with constructors that have arguments.
Tasks
Summary by CodeRabbit
New Features
Tests