Skip to content

fix(types): insert on an untyped schema rejects every primitive field value #52

Closed

Description

@Upd4ting

Schema.get("myapp") and new Schema("myapp", {...}) without a type argument leave T = any, so instance().table("users") is a Table<any>. Table.insert takes DeepPartial<T> | DeepPartial<T>[] (src/staged-query/selection.ts:156), and DeepPartial<any> (src/staged-query/common.ts:13) is a mapped type with no passthrough for primitives. A string, number or boolean field value is therefore not assignable to it, and the documented untyped usage does not compile.

Reproduction (a file in docs/ checked with docs/tsconfig.json, identical on campaign/integration at d4946b0):

import { Schema } from "@antelopejs/interface-database";

const users = Schema.get("myapp")!.instance().table("users");
await users.insert({ name: "John Doe" });

tsc -p docs/tsconfig.json --noEmit reports:

error TS2322: Type 'string' is not assignable to type 'DeepPartial<any> | DeepPartial<unknown>[] | readonly DeepPartial<unknown>[] | undefined'.

The same call with a typed schema compiles: Schema.get<{ users: { _id: string; name: string } }>("myapp")!.

Expected: either an untyped schema accepts any document (DeepPartial<any> resolves to any), or the docs only show typed schemas. docs/2.operations/5.indexes.md, docs/3.results/1.index.md and docs/3.results/2.write_results.md showed the untyped form; the docs now type the schema, so this issue changes no docs.

Suggested fix: make DeepPartial<T> return T for primitives and any (for example 0 extends 1 & T ? any : ...), then add a type test for insert and update on a Table<any>.

Activity

  1. Upd4ting commented on Nov 4, 2026

    @Upd4ting
    MemberAuthor

    Fixed by #59 (typed write documents), on main in 1cf8db2 (#71). DeepPartial<any> now resolves through DeepPartialValue in src/staged-query/common.ts. Checked: tsc on main accepts Schema.get("myapp")!.instance().table("users").insert({ name: "John Doe" }) on an untyped schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions