sequelize-auto
sequelize-auto copied to clipboard
No type inference for 'create' association ?
Suppose I have a model
class user extends Model<... >
{
// User hasOne UserCredentials via idUser
userCredential!: UserCredentials;
getUserCredential!: Sequelize.HasOneGetAssociationMixin<UserCredentials>;
setUserCredential!: Sequelize.HasOneSetAssociationMixin<UserCredentials, UserCredentialsId>;
createUserCredential!: Sequelize.HasOneCreateAssociationMixin<UserCredentialsCreationAttributes>;
}
The createUserCredential
does not have type inferences for its properties.
export type HasOneCreateAssociationMixin<TModel> = (
values?: { [attribute: string]: unknown },
options?: HasOneCreateAssociationMixinOptions
) => Promise<TModel>;
Shouldn't the values
type infer from the UserCredential
class instead of being unknown
?
Also if I make a call like user.createUserCredential({})
. What should the keys be? the properties of the model or the column names in the DB ?
Hmm. I thought that declaring createUserCredential
as
Sequelize.HasOneCreateAssociationMixin<UserCredentialsCreationAttributes>
would somehow cause the values
parameter to be the appropriate creation type, i.e. UserCredentialsCreationAttributes
@steveschmitt Is there anything I can do about it for now ? because all this is autogen, I am skeptical to modify any generated-stuff myself. But this issue is rather annoying as there is no member-inference. should the values
type be defined as UserCredentialsCreationAttributes
instead of { [attribute: string]: unknown }
?. If so I can change it manually now.
Is this a bug that will be fixed ?
As far as this link goes : https://sequelize.org/master/class/lib/associations/has-one.js~HasOne.html
The type of the values seems to be Object
by default. Is there where the issue lies perhaps ?