Function: Default()
Default(
value):PropertyDecorator
Defined in: src/decorators/Default.ts:23
Property decorator designating a default value or generator function for an entity property.
The default is applied automatically when inserting new records if the property is undefined,
and is emitted into table definitions during Code-First schema generation (ensureCreated()).
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | Literal value or a generator function (e.g. () => new Date(), () => uuid()). |
Returns
PropertyDecorator
Usecase
Auto-populate defaults such as active flags, initial counters, or timestamp generators.
Example
@Default('active')
status!: string;
@Default(0)
points!: number;
@Default(() => new Date())
createdAt!: Date;