-
Notifications
You must be signed in to change notification settings - Fork 286
Improve any types for values/records in Models.d.ts #239
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
Comments
Hey @Danlock. You mean this https://github.com/RobinBuschmann/sequelize-typescript/blob/master/lib/models/Model.d.ts#L308 ( |
@RobinBuschmann currently i use Partial<Pick<T, 'id' | 'etc'>> |
So every time you use a method like create, you have a big list of all the attributes right next to the function call? That sounds cumbersome, but I guess it's more typesafe. Is it possible to select against subset of Model keys that are always there so that the remainder are 'legit' columns? Something like a Difference of keys between whatever Model is being passed in vs the standard Model functions and attributes we know is always there.
If this is not possible, Partial might be the only practical solution without any knowledge of the user's attributes. |
Ok, so I looked around for type differences and stumbled upon microsoft/TypeScript#18567. With that I think I found the closest solution to getting the attributes for typesafety without needing to manually specify database columns.
This will remove almost all of the already known methods from the Model instance, allowing the user's predefined columns to remain. One caveat is the sequelize defined attributes will remain as type any. For example, even if your Model just has { id: string }, using GetAttributes will result in I could omit these types as well, but that would screw over people who use them, which would be a lot of people i imagine. Unless there are any objections I think ill submit a pull request sometime this week, essentially replacing the |
Sounds good. What about
|
Sure, I can do that instead. I will be leaving those fields as type any though, since the user can use those fields for whatever they want. |
The types for functions that have to do with creation such as Model.create or Model.build have a any type on their values: parameters. Is there a reason why that can't be Partial to get some compile time verification of model attributes on such methods?
I know that this includes function names as well, but it's better than any.
I'm going to do this on my project anyway, so let me know if you would accept a PR for this.
The text was updated successfully, but these errors were encountered: