Skip to content
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

fix(adonis-typings): return type of mixin #1

Closed
wants to merge 1 commit into from

Conversation

lukfor85
Copy link

Proposed changes

Hence the mixin is not adding any instance methods, the return type of a constructor should be an empty object. Before the fix, we could not use this package with a model that extends a class that inherits from BaseModel.

an example that didn't work without the fix:

import { BaseModel } from '@ioc:Adonis/Lucid/Orm';

class ModifiedBase extends BaseModel {
    // some basics
}

class Bank extends compose(ModifiedBase, AutoPreload) {
    // model properties
}

Types of changes

What types of changes does your code introduce?

Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added the necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@Melchyore Melchyore self-requested a review December 16, 2022 17:46
@Melchyore
Copy link
Owner

@lukfor85 Hello!

Thank you for the PR. However, before I merge it, can you please make the mixin return LucidModel instead of an empty object? Because it doesn't return an empty object and you'll still have the same bug. Also, can you please remove the changes done on package.json and not commit the package-lock.json file?

@lukfor85
Copy link
Author

@lukfor85 Hello!

Thank you for the PR. However, before I merge it, can you please make the mixin return LucidModel instead of an empty object? Because it doesn't return an empty object and you'll still have the same bug. Also, can you please remove the changes done on package.json and not commit the package-lock.json file?

Hello, thank you for the review. Regarding the package.json and package-lock.json - no problem I can roll back the changes. When it comes to adonis-typings/auto-preload.ts, rolling back the changes means my PR is useless :). But I want to talk about it more deeply. From my knowledge, mixin is not an instance of the model, it's just a programming structure that adds more methods aside from the inheritance. So writing

new (...args: Array<any>): LucidModel;

is not actually true. The correct way is to write only properties you add to the actual model instance. Like that:

new (...args: Array<any>): {
   newProperty(): any;
}

Firstly, please check the other Adonis mixin packages (soft-deletes, select-related, etc...) and how they deal with it. I've checked a couple of them and their typings are defined exactly as I fixed it in your package. As your package is not adding any property to the model instance itself (only static methods though), your return type should be an empty object.

Secondly, please have a look at my example above. Make your own BaseModel (call it whatever you want), inherit a model from it and then use your AutoPreload. From what I experienced, your package is usable only if you inherit directly from Adonis' default BaseModel and that is not ok IMHO. Mixin should be usable on every place of the inheritance structure.

@Melchyore
Copy link
Owner

@lukfor85 Hey! Some changes had to be made, so I will close this PR. Please upgrade to v1.0.5.

@Melchyore Melchyore closed this Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants