Minimal single-repo repro for a Parse TypeScript typing issue, with a tiny runtime demo.
Parse currently types Query.containedIn() incorrectly for array-valued fields.
This code is included in repro/parse-containedin-type-bug.ts:
import Parse from 'parse';
type ItemAttributes = {
title: string;
areaIds: string[];
};
type ItemBase = Parse.Object<ItemAttributes>;
const Item = Parse.Object.extend('Item');
const query = new Parse.Query(Item) as Parse.Query<ItemBase>;
query.containedIn('title', ['one', 'two']);
// @ts-expect-error Parse currently types this incorrectly for array-valued fields.
query.containedIn('areaIds', ['A1', 'A2']);title(scalar field) type-checks.areaIds(string[]) needs@ts-expect-errortoday.- If Parse fixes typings later, this
@ts-expect-errorbecomes unused and typecheck will fail, which is desired.
The frontend runs:
query.containedIn('areaIds', ['A1', 'A2']);against seeded rows:
{ title: 'matches-a1', areaIds: ['A1', 'B3'] }{ title: 'matches-a2', areaIds: ['A2'] }{ title: 'no-match', areaIds: ['B3', 'C4'] }
Expected runtime result:
- ✅
matches-a1 - ✅
matches-a2 - ❌
no-match
- Next.js + TypeScript frontend (
http://localhost:3000) - Programmatic Parse Server (
http://localhost:1337/parse) mongodb-memory-serverfor fully local, in-memory MongoDBconcurrentlyto run both processes from one command
Parse server starts with:
appId: devmasterKey: dev-master-keyjavascriptKey: dev-js-keyserverURL: http://localhost:1337/parseallowClientClassCreation: true
CORS is enabled for http://localhost:3000.
npm install
npm run devThen open http://localhost:3000 and use:
- Seed sample data
- Run overlap query
- Clear sample data
Type-check the repro file:
npm run typecheckOptional production build check:
npm run buildThis repo also includes a local patch-package patch for the Parse typings at patches/parse+8.6.1-alpha.1.patch.
The workflow is intentionally manual:
npm installdoes not apply the patch automatically.- The installed
parsepackage stays in its upstream broken state first, so the repro still errors during type-checking. - You can apply the local fix manually when you want to verify the patched behavior.
Apply the patch manually:
npx patch-packageUnapply the patch manually:
npx patch-package --reverseHow it works:
- The patch file records the diff against
node_modules/parse/types/ParseQuery.d.ts. - Running
npx patch-packagereapplies that diff intonode_modules. - Running
npx patch-package --reverseremoves it again.
The patch updates Parse query typings so these methods use an array field's element type instead of the whole array type:
containedInnotContainedIncontainedBycontainsAll
That is what fixes the string[][] inference problem for fields like areaIds: string[] while preserving pointer support.
- Type bug reproduction:
repro/parse-containedin-type-bug.ts - Parse server bootstrap:
server/parse-dev.ts - Runtime overlap demo UI:
src/app/page.tsx