T
TanStack7d ago
correct-apricot

How to get ctx.meta?.loadSubsetOptions type safe?

The type of meta being Record<string, unknown> | undefined, loadSubsetOptions is typed unknown. Is there a way to make it type safe or I should just cope with @ts-ignore?
createCollection(
queryCollectionOptions({
queryKey: orpc.missions.steps.answers.list.queryKey(),
syncMode: "on-demand",
queryFn: (ctx) => {
// ts error: Argument of type 'unknown' is not assignable to parameter of type '{ where?: BasicExpression<boolean> | undefined; orderBy?: OrderBy | undefined; limit?: number | undefined; } | null | undefined'.
const options = parseLoadSubsetOptions(
ctx.meta?.loadSubsetOptions
);
return orpc.missions.steps.answers.list.call(options);
},
queryClient,
getKey: (item) => item.id,
})
)
createCollection(
queryCollectionOptions({
queryKey: orpc.missions.steps.answers.list.queryKey(),
syncMode: "on-demand",
queryFn: (ctx) => {
// ts error: Argument of type 'unknown' is not assignable to parameter of type '{ where?: BasicExpression<boolean> | undefined; orderBy?: OrderBy | undefined; limit?: number | undefined; } | null | undefined'.
const options = parseLoadSubsetOptions(
ctx.meta?.loadSubsetOptions
);
return orpc.missions.steps.answers.list.call(options);
},
queryClient,
getKey: (item) => item.id,
})
)
7 Replies
extended-salmon
extended-salmon6d ago
we weren't doing this automatically — can you try out the package built here? https://github.com/TanStack/db/pull/869
GitHub
Make ctx.meta.loadSubsetOptions type safe by KyleAMathews · Pull R...
Previously, the module augmentation for @tanstack/query-core that makes ctx.meta?.loadSubsetOptions type-safe was in query.ts. This meant it wasn&amp;#39;t always processed by TypeScript unless som...
correct-apricot
correct-apricotOP5d ago
sry didn't get the notification, checking that right now it seems like the build does not include the global.d.ts, so the module augmentation is not loaded here's how @tanstack/query-db-collection looks like:
├── dist
│ ├── cjs
│ │ ├── errors.cjs
│ │ ├── errors.cjs.map
│ │ ├── errors.d.cts
│ │ ├── index.cjs
│ │ ├── index.cjs.map
│ │ ├── index.d.cts
│ │ ├── manual-sync.cjs
│ │ ├── manual-sync.cjs.map
│ │ ├── manual-sync.d.cts
│ │ ├── query.cjs
│ │ ├── query.cjs.map
│ │ ├── query.d.cts
│ │ ├── serialization.cjs
│ │ ├── serialization.cjs.map
│ │ └── serialization.d.cts
│ └── esm
│ ├── errors.d.ts
│ ├── errors.js
│ ├── errors.js.map
│ ├── index.d.ts
│ ├── index.js
│ ├── index.js.map
│ ├── manual-sync.d.ts
│ ├── manual-sync.js
│ ├── manual-sync.js.map
│ ├── query.d.ts
│ ├── query.js
│ ├── query.js.map
│ ├── serialization.d.ts
│ ├── serialization.js
│ └── serialization.js.map
├── LICENSE
├── package.json
└── src
├── errors.ts
├── global.d.ts
├── index.ts
├── manual-sync.ts
├── query.ts
└── serialization.ts
├── dist
│ ├── cjs
│ │ ├── errors.cjs
│ │ ├── errors.cjs.map
│ │ ├── errors.d.cts
│ │ ├── index.cjs
│ │ ├── index.cjs.map
│ │ ├── index.d.cts
│ │ ├── manual-sync.cjs
│ │ ├── manual-sync.cjs.map
│ │ ├── manual-sync.d.cts
│ │ ├── query.cjs
│ │ ├── query.cjs.map
│ │ ├── query.d.cts
│ │ ├── serialization.cjs
│ │ ├── serialization.cjs.map
│ │ └── serialization.d.cts
│ └── esm
│ ├── errors.d.ts
│ ├── errors.js
│ ├── errors.js.map
│ ├── index.d.ts
│ ├── index.js
│ ├── index.js.map
│ ├── manual-sync.d.ts
│ ├── manual-sync.js
│ ├── manual-sync.js.map
│ ├── query.d.ts
│ ├── query.js
│ ├── query.js.map
│ ├── serialization.d.ts
│ ├── serialization.js
│ └── serialization.js.map
├── LICENSE
├── package.json
└── src
├── errors.ts
├── global.d.ts
├── index.ts
├── manual-sync.ts
├── query.ts
└── serialization.ts
as you can see, global.d.ts is not included in the builds, but it's imported by esm/index.d.ts and cjs/index.d.cts
extended-salmon
extended-salmon5d ago
ok thanks for trying — pushed another commit which hopefully fixes it — please try that
correct-apricot
correct-apricotOP4d ago
nice!
No description
correct-apricot
correct-apricotOP4d ago
thank you @Kyle Mathews
extended-salmon
extended-salmon4d ago
Nice! Could you post that on the issue btw?
correct-apricot
correct-apricotOP4d ago
sure

Did you find this page helpful?