-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add support for custom types to "typeorm-typescript/enforce-column-types" #5
Comments
I detailed in another comment (#4 (comment)) what is the issue with aliases. However I could imagine an option in the ESLint configuration, where you could add custom aliases: {
"rules": {
"typeorm-typescript/enforce-column-types": ["error", {
"customTypes": {
"UUID": "string"
}
}]
}
} It would be riskier, but there could even be a built-in mapping of well-known types, that is validated automatically (for example somebody redefining UUID to store it as an object). However I'd prefer to get this first as an opt-in feature. Would this be what you had in mind? |
This idea here could be an intermediate step towards full type support (as I suggested in my comment on #4). It's not quite type-safe, but I guess that's something I'd have to live with then 😅 My database-layer anyways won't be 100% type safe, because I cannot create a rule by which it would check for my uuid pattern, so I'll always have to rely on e.g. that my application is the only thing modifying the database. |
I added some support for type safety in v0.3.0 so it should now handle aliases (your UUID example should work as well). Thank you for your suggestion! |
What about this? |
Can you link me a documentation that shows that |
This may depend on both the internal default settings of typeorm and the specific settings of the driver, and on the settings set by the developer. Example for typeorm usage with custom
|
I tested Typeorm with the most popular drivers (pg, mysql2, sqlite3), and I found that you are indeed correct. It gives different outputs for different drivers:
I would guess this is based on SQLite's lack of different sized int and float columns. I'm not sure how to proceed, I'm wary of adding new configurations for every change, which would nudge me towards accepting both string and number. On the other hand, that would add to the confusion that this library is supposed to solve. Do you think a |
Hey @norbornen, I created a new PR #19, which changes the default behaviour to follow your use-case. Can you follow up, if this is fixed for you? I can merge it for the next release. |
I released the fix for bigint and decimal in version v0.5.0. If you have any more issues, feel free to reopen. Thanks for your help! |
I'd love to get an option to define things like
import { UUID } from 'crypto';
as compatible tostring
. This way I could take advantage of the null-checking here!The text was updated successfully, but these errors were encountered: