While using the sequelize-typescript npm
When trying to invoke the Street.create(obj)
I get an error:
Argument of type 'plainObject' is not assignable to parameter of type 'Optional<Street, NullishPropertiesOf>'. Type 'plainObject' is missing the following properties from type 'Omit<Street, NullishPropertiesOf>': sequelize, destroy, restore, update, and 39 more
This is the model:
import { Table, Model, Column, PrimaryKey } from 'sequelize-typescript';
@Table({ timestamps: false, tableName: 'street' })
class Street extends Model<Street> {
@PrimaryKey
@Column
street_id: string;
@Column
location_id: string;
@Column
location_symbol: string;
@Column
street_name: string;
@Column
street_synonym: string;
@Column
street_symbol: string;
@Column
updated: Date;
}
export default Street;
this is the call
Street.create({
location_id: 'string',
location_symbol: 'string',
street_name: 'string',
street_synonym: 'string',
street_id: 'string',
street_symbol: 'string',
updated: new Date(),
});
create
orbulkCreate
. I'd recommend the other answer to avoid breaking the type system. – Ostrom