Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Typescript complain with compound ID

Open tobiasBora opened this issue 1 year ago • 2 comments

I tried to create a combound key using:

export interface Foo {
  bar: string,
  baz: string;
}

export class MyDexie extends Dexie {
  foos!: EntityTable<Foo, '&[bar+baz]'>;

  constructor(name : string) {
    super(name);
    this.version(1).stores({
      foos: '&[bar+baz]', // Primary key and indexed props
    });
  }
}

but I get an error:

Error: Type '"bar+baz"' does not satisfy the constraint 'keyof Foo'. 
  foos!: EntityTable<Foo, '&[bar+baz]'>;

is this a bug or am I missing something?

tobiasBora avatar May 12 '24 17:05 tobiasBora

EntityTable currently only supports single property primary keys. Try with Table<Foo, [string,string]> instead

dfahlander avatar May 14 '24 21:05 dfahlander

Thanks, but then I guess I will not have type safety for insertion etc. I guess I'll just use an id, and then create an index to efficiently get it

tobiasBora avatar May 14 '24 21:05 tobiasBora