-
Notifications
You must be signed in to change notification settings - Fork 62
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
Unable to register Typescript Model #142
Comments
Maybe the example isn't quite clear here, since its only supposed to show the typing stuff, not how to generally use nohm. I'll look into fixing that. nohm.register returns the class you are supposed to use, as explained here. In the grand scheme a bigger refactoring to make this work with just the extended model would probably be good. I'm not sure anymore why I didn't change that back when I rewrote all of it for v2. Here's the continuation of that example that will make use of the registered model: const userModelStatic = Nohm.register(UserModel);
// some wrapping to make it work in a single file with async/await
const main = async () => {
await redisConnector(); // a custom helper
try {
const user = new userModelStatic();
user.property({ email: `foobar@example.com` });
await user.save();
try {
const user2 = new UserModel(); // wrong invocation
await user2.save(); // will not be reached
console.error('This line should never appear!');
process.exit(1);
} catch (e) {
console.info('As expected it failed:', e);
}
} finally {
await redisCloser(); // a custom helper
}
};
main().catch((err) => {
console.error('Unexpected failure:', err);
}); |
Sorry, I'm sick right now, my brain doesn't work quite right. The documentation is clearly missing that as well. |
@maritz no problem at all, thank you for the speedy response and for maintaining this package! If I end up writing good documentation internally I may submit a PR. |
The Typescript example shows the following:
However, when using this exact setup I receive the following error:
Error: Class is not extended properly. Use the return Nohm.register() instead of your class directly.
I am on Node
v8.16.0
Tsconfig:
Any help is appreciated.
The text was updated successfully, but these errors were encountered: