From 8faaee532c0da14ea9459bd4138ae2cb2a66ed5b Mon Sep 17 00:00:00 2001 From: Waseem Alhalabi <217769131+walhalabi-code@users.noreply.github.com> Date: Mon, 31 Aug 2026 14:32:41 +0300 Subject: [PATCH] Stop the test template pulling a second set of Parse types The test file added in 3.0.2 began with a typed import: import Parse from 'parse/node'; That put the type definitions the parse package ships into a project whose every other file uses the @types/parse global. The two disagree - getSessionToken() is string in one and string | null in the other - so a project could see errors about its own code that were really a clash between two definitions of the same API, in a file the user never opened. tsc tolerated it, which is why it was not caught: the generated project compiled cleanly the whole time. Editors need not be so forgiving, and an error that points at your code while originating somewhere else is the hardest kind to act on. Now a require, which sets the global without introducing a second source of types. Parse in that file means what it means everywhere else. The SDK still has to be on the global before any model is imported, because @ParseClass registers the subclass while the module is evaluated - the require does that just as well. Verified: a generated project compiles, its five tests pass, and no file imports parse's own types. --- package-lock.json | 4 ++-- package.json | 2 +- templates/default/src/note.test.ts | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index b6ce350..907cacc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "parse-server-kit", - "version": "3.0.4", + "version": "3.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "parse-server-kit", - "version": "3.0.4", + "version": "3.0.5", "license": "MIT", "bin": { "parse-server-kit": "dist/cli/index.js", diff --git a/package.json b/package.json index 87f0ba3..89ec2fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "parse-server-kit", - "version": "3.0.4", + "version": "3.0.5", "description": "Decorator-driven toolkit for Parse Server: models, cloud functions, triggers, cron, REST routing, ACL, transactions, optimistic locking and Swagger, from TypeScript decorators.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/templates/default/src/note.test.ts b/templates/default/src/note.test.ts index 1100d82..a9ee1e9 100644 --- a/templates/default/src/note.test.ts +++ b/templates/default/src/note.test.ts @@ -2,8 +2,24 @@ import {test, describe} from 'node:test'; import assert from 'node:assert/strict'; import './env'; -import Parse from 'parse/node'; -(global as unknown as {Parse: typeof Parse}).Parse = Parse; + +/* + * `require`, not `import`. + * + * The SDK has to be on the global before a model is imported, because + * `@ParseClass` registers the subclass while the module is being evaluated. + * + * A typed `import Parse from 'parse/node'` would do that too — but it also + * pulls in the type definitions the `parse` package ships, which disagree with + * `@types/parse` that the rest of the project uses. `getSessionToken()` is + * `string` in one and `string | null` in the other, and having both in a + * project produces errors that point at your code rather than at the clash. + * + * Requiring it sets the global without introducing a second source of types, + * so `Parse` here means the same thing it means everywhere else. + */ +// eslint-disable-next-line @typescript-eslint/no-var-requires +(global as unknown as {Parse: unknown}).Parse = require('parse/node'); import Note from './models/Note';