-
-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Describe the feature
Hi,
I wanted to implement a type-safe method to insert data into the repository. But after checking the type definitions of pinia-orm, I haven't found a type that will represent the basic state of the model. I was expecting to find something like: Record<keyof Model, any>
Lets take a look at this example:
export class Song extends Model {
static entity = 'song';
@Uid()
declare id: string;
}
add(song: Song) {
this.repo.insert(song);
}
If I try to insert data into repo, I will get the following error:
Argument of type '{}' is not assignable to parameter of type 'Song'.
Type '{}' is missing the following properties from type 'Song': id, _meta, $self, $entity, and 39 more.
Yes, I can use Element istead of Song as type of parameter, but this type is not type-safe, it doesn't represent actual model field.
Can you create a type that will allow me to insert data type-safe?
Bad:
.add({ id: 1, foo: 'bar' }) //BAD
.add({ id: 1, }) //GOOD
Additional information
- Would you be willing to help implement this feature?
Final checks
- Check existing discussions and issues.