sequelize-auto
sequelize-auto copied to clipboard
Model generated - Declaring public class fields error - Typescript
I'm generating models with these switches on --cp p --cf p --cm p
.
After the models are initialized, while querying, sequelize produces the following error.
(sequelize) Warning: Model "UsersToRoles" is declaring public class fields for attribute(s): "IdUser", "IdRole", "RoleName"
The model file has the following data generated..
export interface UsersToRolesAttributes {
IdUser: number;
IdRole: number;
RoleName?: string;
}
export class UsersToRoles extends Model<UsersToRolesAttributes, UsersToRolesCreationAttributes> implements UsersToRolesAttributes {
IdUser!: number;
IdRole!: number;
RoleName?: string;
.
.
.
.
Bunch of other stuff
static initModel (sequelize: Sequelize.Sequelize): typeof UsersToRoles {
return UsersToRoles.init({
IdUser: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
references: {
model: "user",
key: "id_user"
},
field: "id_user"
},
.
.
.
.
}
As given here, If I add declare
in front of the properties. The error goes away.
export class UsersToRoles extends Model<UsersToRolesAttributes, UsersToRolesCreationAttributes> implements UsersToRolesAttributes {
declare IdUser: number;
declare IdRole: number;
declare RoleName?: string;
Using [email protected]
and [email protected]
This issue did not occur in older versions with the same schema.... I upgraded sequelize and sequelize auto and this issue showed up.
Any help would be appreciated.
Also, all the HasOne, HasMany
getter/setter functions are undefined !!
I am currently manually using declare
keyword everywhere. It becomes a pain because there are sooo many tables and having to manually do changes to all the files defeats the purpose of using sequelize-auto
in the first place.
According to https://sequelize.org/master/manual/typescript.html. We do need to use declare
everywhere. Hmm.
Yeah, the later versions of typescript are making things harder.
Any update on this? How can I solve this problem?