Modifiable<T>

Represents the type for a modifiable entry from a Collection

This type was introduced in version 2.11.0. By using this type in type assertions, it ensures that your code has the correct typings, allowing you to modify an entry's data directly and then to use the new Data#save method.

TypeScript declaration:

type Modifiable<T> = T & {
  save(): void;
}

Example TypeScript usage:

import { Database, Modifiable } from 'simpl.db';
const db = new Database();

type User = {
  name: string
  age: number
}

const Users = db.createCollection<User>('users');

Users.create({ name: 'Peter', age: 19 });

const user = <Modifiable<User>> Users.get(target => target.name === 'Peter');

user.age = 20;
user.save(); // If you don't use type assertion like above, this will error

Last updated