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 complain with compound ID #1990

Open
tobiasBora opened this issue May 12, 2024 · 2 comments
Open

Typescript complain with compound ID #1990

tobiasBora opened this issue May 12, 2024 · 2 comments

Comments

@tobiasBora
Copy link
Contributor

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?

@dfahlander
Copy link
Collaborator

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

@tobiasBora
Copy link
Contributor Author

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

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