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

Compile error when calling modify on a table with generic types #1951

Open
wb-rs opened this issue Apr 3, 2024 · 0 comments
Open

Compile error when calling modify on a table with generic types #1951

wb-rs opened this issue Apr 3, 2024 · 0 comments

Comments

@wb-rs
Copy link

wb-rs commented Apr 3, 2024

When modifying a table with a generic parameter that extends a type, I get a compile error:

import Dexie, { Table } from 'dexie';

interface Entity {
  id: string;
  property: string;
}

export abstract class AbstractStorageService<T extends Entity> extends Dexie {
  protected readonly items: Table<T, string>;

  protected constructor(databaseName: string) {
    super(databaseName);
  }

  async modifyProperty(id: string, value: string): Promise<void> {
    // This line does not compile.
    await this.items.where({ id }).modify({ property: value });
  }
}

When the table does not have a generic parameter, it compiles just fine:

import Dexie, { Table } from 'dexie';

export abstract class StorageService extends Dexie {
  protected readonly items: Table<Entity, string>;

  protected constructor(databaseName: string) {
    super(databaseName);
  }

  async modifyProperty(id: string, value: string): Promise<void> {
    // This line compiles.
    await this.items.where({ id }).modify({ property: value });
  }
}

I think both cases should be fine. Am I missing something? 🤔

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

1 participant