Skip to content

Dexie v4.0.1-alpha.7

Pre-release
Pre-release
Compare
Choose a tag to compare
@dfahlander dfahlander released this 25 Jan 20:26
· 355 commits to master since this release

Typings fix for Table.update(), Table.bulkUpdate() and Collection.modify()

In Dexie 4.0.1-alpha.6, Table.bulkUpdate() was introduced as well as improving the typings of Table.update(), Collection.modify() to using typescript template literals that would correcltly type the changes argument and provide a nice code completion. However, there was a typings bug in this release that made the typings unusable for updating nested properties.

This version fixes the typings of Table.update(), Table.bulkUpdate() and Collection.modify() so that they work according to the expected format.

Requires Typescript 4.8 or later

The typings in this release requires Typescript 4.8 or later in order to accept numeric keypaths and allow updating individual array items.

The UpdateSpec type

A new type UpdateSpec<T> is expected as the second argument to Table.update(). This type can also be imported from dexie when the library user need to build the updateSpec using custom code before finally send along to Table.update() or in an array keysAndChanges to Table.bulkUpdate().

import type { UpdateSpec } from 'dexie';

interface Contact {
  name: string;
  address: Address;
}

interface Address {
  city: string;
  street: string;
  streetNo: number;
}

let updateSpec: UpdateSpec<Contact> = {};

updateSpec["address.streetNo"] = 44;

db.contacts.update(1, updateSpec);