-
Notifications
You must be signed in to change notification settings - Fork 285
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
Model.create() Values autocomplete is missing? #858
Comments
It's a bit awkward, since a while ago sequelize-typescript offered said completions (0.6 I think), then they removed when Sequelize@5 added official Typescript support (but without completions) and now Sequelize@6 has full completions (using a hidden property called So currently, the maintainer of this library seems to be inactive, and you get better support of types sticking to the official (ironically). |
I had the same issue, and I solved it by creating a type for my model maybe you need two one for TModelAttributes and another for TCreationAttributes, and then do like this (I forgot how it calls in typescript 😅). then the completion works fine. type User = {
id: number;
username: string;
//...
}
type CUser = Omit<User, 'id'>
class User extends Model<User, CUser> {
@Column
//..
} |
@AbderrazzakB That's pretty much how sequelize@6 recommends it, and it properly fills the The only issue you'll run is when attempting to do relations, where the, for example, For now, I think the only solution is that, and cast to any to cover it up. For Example: interface UserAttributes {
id: string
name: string
}
type UserCreationAttributes = Omit<UserAttributes, 'id'> // id is auto-generated.
@Table({ ... })
class User extends Model<UserAttributes, UserCreationAttributes> { // <-- we add the type info for Sequelize@6.
@Column({ type: DataTypes.UUIDV4 })
id!: string
@Column({ type: DataTypes.TEXT, allowNull: true })
name!: string | null
// Here we cast to any so seq-typescript doesnt cry
@BelongsToMany(() => Post as any, () => UserPost as any)
readonly posts?: Array<Post>
} You can check the types work in VSCode by doing: type X = User['_attributes']['<autocomplete here>'] The value of |
No way that the lib that calls itself That's sad! |
No way, is there any another way to solving this? I think that I'm going for prisma |
Am i missing something or is there no autocomplete on
new Model({...})
,Mode.create({...})
orModel.build({...})
...I added the columns to my Models as shown in the documentation, but when i go to create a Model and i start typing the Class members, they do not auto complete..
Shouldn't it work like this?
This guy did the sequelize tyescript integration manually and it seems like a lot of dirty work to make it work. If this is not something integrated with this package, would it be hard to implement so that we get auto complete?
The text was updated successfully, but these errors were encountered: