Avoid code duplication when using a strongly typed model
See original GitHub issueSummary:
How can I avoid duplicating the schema definition if I want a strongly typed model? It can become areal nightmare if your schema has heaps of properties.
Schema
const userSchema = new dynamoose.Schema({
"id": String,
"name": String,
"age": Number
})
class User extends Document {
// <--- DRY? --->
id: string;
name: string;
age: number
// <------------>
}
Model
const UserModel = dynamoose.model<User>("User", userSchema);
Environment:
Node.js version: v12.19.0
NPM version: (npm -v
): 6.14.8
Dynamoose version: 2.4.1
Other:
- [ x ] I have read through the Dynamoose documentation before posting this issue
- [ x ] I have searched through the GitHub issues (including closed issues) and pull requests to ensure this question has not already been raised before
- [ x ] I have searched the internet and Stack Overflow to ensure this question hasn’t been raised or answered before
- [ x ] I have filled out all fields above
- [ x ] I am running the latest version of Dynamoose
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
The key to eliminating duplicated code patterns - Medium
“Sloppiness”, “carelessness” and “sheer unprofessionalism” are strong words, but it goes to underline the importance of not duplicating code.
Read more >How to avoid code duplication from handling "structually ...
You're trying to codify a relationship between the types, when in reality, you just need to extract an id , which can be...
Read more >Avoiding duplicate code when performing operation on ...
"The real question is how to avoid code duplication when performing an identical operation on two different properties of an object.".
Read more >How to avoid code duplication in MVVM? - MSDN - Microsoft
In MVVM people seem to suggest that the model should not be bloated out and that logic should be put in the view...
Read more >The Impact of Duplicate Code - Level Up Coding
The most effective way to prevent duplicate code from slipping into the codebase is by dividing code and logic into smaller reusable units....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@RickvdP I did see that recently. Sadly, we just need more support to make it happen.
v3, still has a bit to go before release. Tho we are getting closer.
Yes. I think v4 support for this using TypeScript Decorators would be great along with bringing TypeScript out of beta. Seems like a great idea.
@fishcharlie I agree too, but I think there is no easy way to do that yet, however I will definitely spend sometime on it later. here is some discussion about this topic https://stackoverflow.com/questions/45771307/typescript-dynamically-create-interface