Skip to content

Generics for the model attributes? #125

Open
@rokoroku

Description

@rokoroku

Why don't we have generic for the model attributes?
e.g.

interface TypedModelAttributes {
  id: number;
  optionalData?: object;
}

class TypedModel extends Model<TypedModelAttributes> {
  ...
}

// usage
TypedModel.build({ ... }) // will be type-checked by "TypedModelAttributes"
TypedModel.findOne({ where: { ... }) // will be type-checked by "keyof TypedModelAttributes"
...

It is more accurate and will bring a lot of conveniences than current <K extends keyof this> way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions