What is the correct way to specify a null column with sequelize-typescript?

Viewed 324

I cannot see any documentation on how to specify the javascript type of NULL columns in sequelize-typescript.

For example (the default @Column is allowNULL=true):

@Column
my_property?: string | null
my_other_property: string | null

both results in the following error Specified type of property 'my_property' cannot be automatically resolved to a sequelize data type.

Am I doing something wrong, or is the correct way merely:

@Column
my_property?: string

In which case, what does the ORM return when the database value is NULL? Does my_property become null or undefined?

Any tips are appreciated.

1 Answers

The first way is correct with regards to null and works for some columns as of sequelize-typescript@2.1.3. The error is because you did not specify the column data type, and there are multiple column types that could correspond to a JS string type and the fallback code is not able to pick one. I recommend always specifying the column's data type to make this clear:

@Column({ type: DataType.STRING })
my_property?: string | null
Related