Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error with db.table.update() or bulkUpdate() #2026

Open
laukaichung opened this issue Jul 1, 2024 · 1 comment
Open

Typescript error with db.table.update() or bulkUpdate() #2026

laukaichung opened this issue Jul 1, 2024 · 1 comment

Comments

@laukaichung
Copy link

laukaichung commented Jul 1, 2024

Updated:

I just found that the 2D array field teamIdPairsis the culprit. Is there anything I can do to remove this type error without changing teamIdPairs?


Hello,
I ran into a typescript error with db.table.update() or db.table.bulkUpdate(). It complains that the changes values have issues:

TS2322: Type number is not assignable to type void | PropModification | undefined dexie.d.ts(388, 29): The expected type comes from property activated which is declared here on type

This is the main code:


export interface Playlist {
  year: number;
  competitionId: number;
  stageId: number;
  teamIdPairs: number[][];
  activated: number;
}

export class MySubClassedDexie extends Dexie {
  playlists!: Table<Playlist>;

  constructor() {
    super("myDatabase");
    this.version(VERSION)
      .stores({
        playlists: "[year+competitionId+stageId]",
      })
      .upgrade(async () => {
        await db.playlists.update([2026, 3, 4], {
          activated: 1, <<------------------- Error here
        });
      });
  }
}

const defaultPlaylists: Playlist[] = [
  {
    year: 2026,
    competitionId: 3,
    stageId: 4,
    teamIdPairs: [[1, 2]],
    activated: 0,
  },
];

Do you see any issues with the table interface Playlist?

Example:
https://codesandbox.io/p/sandbox/dexie-issue-forked-djwxz6?file=%2Fsrc%2Findex.tsx

dfahlander added a commit that referenced this issue Jul 1, 2024
@dfahlander
Copy link
Collaborator

Thanks for the repro. The issue was that the mapped type KeyPaths<T> got into an eternal loop on 2D arrays because the test whether the inner type was an object evaluated true also when the inner type was a nested array and arrays can have an infinite number of keys so the type system had to give up and resolved KeyPaths<Playlist> as a string. KeyPathValue<string> evaluated to undefined/void though (but should probably evaluate to any).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants