sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Updating a Model in a function where two different models with the same attributes are possible

Open schealex opened this issue 4 years ago • 0 comments

Issue

I'm trying to write a function that can update a model and there are two possible models that can be inserted to the function.

Versions

  • sequelize: 6.6.2
  • sequelize-typescript: 2.1.0
  • typescript: 4.3.5

Issue type

  • [x] bug report
  • [ ] feature request

Actual behavior

I'm using the $set functions to update the object. That works fine for most fields but i'm also trying to update a Date type field. The $set only allows for R | R[] | string[] | string | number[] | number | null. I would need to specify the type of the model but i'm getting an error if i try to do that there are missing attributes in the model.

Expected behavior

Be able to use ModelA | ModelB in a function to be able to get or set common attributes.

Steps to reproduce

test(object: ModelA | ModelB) {
   object.$set('commonAttrib', new Date())
}

schealex avatar Oct 04 '21 09:10 schealex