In AdonisJS Lucid ORM, ModelAttributes
is a TypeScript utility type that helps define the shape of a model’s attributes. It filters out functions and relationships from the model attributes and considers all other properties as database columns. This type is particularly useful for ensuring type safety and consistency when working with model attributes.
I want an expert with enough knowledge of the typescript logic, to explain in detail how this ModelAttribute
filters extra fields and only retains main properties.
please explain in basics and detail, thank you.
type ModelAttributes<Model extends LucidRow> = Model['$columns'] extends undefined ? {
[Filtered in {
[P in keyof Model]: P extends keyof LucidRow
| 'serializeExtras' ? never : Model[P] extends Function
| ModelRelationTypes ? never : P;
}[keyof Model]]: Model[Filtered];
} : Model['$columns'];
1