I want to add createdAt and updatedAt to each model on loopback 4
can not find name 'MixinTarget'.
Type parameter 'T' of exported function has or is using private name 'MixinTarget'.
If I try from documentation above error occurs.
I want to add createdAt and updatedAt to each model on loopback 4
can not find name 'MixinTarget'.
Type parameter 'T' of exported function has or is using private name 'MixinTarget'.
If I try from documentation above error occurs.
MixinTaget
must be imported from @loopback/core
:
import {MixinTarget} from '@loopback/core';
import {Class} from '@loopback/repository';
export function TimeStampMixin<T extends MixinTarget<object>>(baseClass: T) {
return class extends baseClass {
// add a new property `createdAt`
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
public createdAt: Date;
constructor(...args: any[]) {
super(args);
this.createdAt = new Date();
}
printTimeStamp() {
console.log('Instance created at: ' + this.createdAt);
}
};
}
As of the writing of this answer, the docs hasn't been updated to reflect the latest clarifications.
To resolve this issue, I didn't use the mixin approach. I added the following fields to my model.
@property({
type: 'date',
default: () => new Date(),
postgresql: {
columnName: 'updated_at',
},
})
updatedAt?: Date;
It should work as expected