Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.
This repository was archived by the owner on Oct 26, 2025. It is now read-only.

Infer types does require id to be set despite it being set as Primary Key and AutoIncrement? #65

@chrisspiegl

Description

@chrisspiegl

I am trying to use d1-orm and the model setup.

I created a model:

new Model(
      {
        D1Orm: orm,
        tableName: 'user_chats',
        primaryKeys: 'id',
        autoIncrement: 'id',
      // uniqueKeys: [['email']],
      },
      {
        id: {
          type: DataTypes.INTEGER,
          notNull: true,
        },
      }
)

My expectation is that then, I can infer the type and it'd know that the id field is kind of optional for inserts and stuff like that?

But doing type UserChats = Infer<typeof models.user_chats>

Followed by a definition if said object:

const userChats: UserChats = {
        }

Shows the type error:

Property 'id' is missing in type '{ }' but required in type 'InferFromColumns<{ id: { type: DataTypes.INTEGER; notNull: true; }; 

I'd hoped that this would just work? Am I missing something? Do I have to update my code somehow to be able to use types with that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions