Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No typesafety with CRUD operations #904

Open
johannbuscail opened this issue Feb 9, 2021 · 6 comments
Open

No typesafety with CRUD operations #904

johannbuscail opened this issue Feb 9, 2021 · 6 comments

Comments

@johannbuscail
Copy link

Hi,
Thanks for this awesome library.
I want to use sequelize-typescript but when I started I faced an issue:

import { Column, Model, Table } from "sequelize-typescript";

@Table
export class User extends Model {
	@Column
	nickname: string;
}

User.findAll({
	attributes: ["blabla"],
});

This doesn't throw an error even tho blabla was never defined.
I have the exact same problem when creating a user:

User.create({
	blabla: "",
        nickname: 88
});

It is totally accepted by the library even tho blabla was never defined and nickname is a number and not a string like defined in the model.
That is the first problem but because of that, the IDE doesn't provide any autocompletion.

Those 2 conditions are the main things Typescript was made for.

@johannbuscail
Copy link
Author

johannbuscail commented Feb 9, 2021

Just figured out that I could do:

@Table
export class User extends Model<User> {
     @Column
     nickname: string
}

Please add this to the docs to make it clear to anyone. I discovered in migration from older version

@johannbuscail
Copy link
Author

After some testing, I found out that this option was terrible. Can you please provide a clean and documented way of being type safe with those operations.

@johannbuscail johannbuscail reopened this Feb 9, 2021
@RoelVB
Copy link

RoelVB commented Feb 15, 2021

I would recommend using the V6 model definitions, but this isn't implemented in v2.0.0 yet. But PR #900 should fix this.

I'm using the V6 model definitions already, it does work, but I had to ignore some TS errors.

@johannbuscail
Copy link
Author

Hi @RoelVB,
Could you give an example of what you mean by V6 model definitions.

@RoelVB
Copy link

RoelVB commented Feb 20, 2021

@johannb75 It's in the readme

@johannbuscail
Copy link
Author

Well it's pretty bad... I get a lot of errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants