Type alias InferAttributes<M, Options>

InferAttributes<M, Options>: {
    [Key in keyof M as InternalInferAttributeKeysFromFields<M, Key, Options>]: M[Key]
}

Utility type to extract Attributes of a given Model class.

It returns all instance properties defined in the Model, except:

  • those inherited from Model (intermediate inheritance works),
  • the ones whose type is a function,
  • the ones manually excluded using the second parameter.
  • the ones branded using NonAttribute

It cannot detect whether something is a getter or not, you should use the Excluded parameter to exclude getter & setters from the attribute list.

Type Parameters

Example

// listed attributes will be 'id' & 'firstName'.
class User extends Model<InferAttributes<User>> {
id: number;
firstName: string;
}

Example

// listed attributes will be 'id' & 'firstName'.
// we're excluding the `name` getter & `projects` attribute using the `omit` option.
class User extends Model<InferAttributes<User, { omit: 'name' | 'projects' }>> {
id: number;
firstName: string;

// this is a getter, not an attribute. It should not be listed in attributes.
get name(): string { return this.firstName; }
// this is an association, it should not be listed in attributes
projects?: Project[];
}

Example

// listed attributes will be 'id' & 'firstName'.
// we're excluding the `name` getter & `test` attribute using the `NonAttribute` branded type.
class User extends Model<InferAttributes<User>> {
id: number;
firstName: string;

// this is a getter, not an attribute. It should not be listed in attributes.
get name(): NonAttribute<string> { return this.firstName; }
// this is an association, it should not be listed in attributes
projects?: NonAttribute<Project[]>;
}