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

Running ember-cp-validations using typescript #702

Open
gabrieltrita opened this issue Jan 13, 2022 · 1 comment
Open

Running ember-cp-validations using typescript #702

gabrieltrita opened this issue Jan 13, 2022 · 1 comment

Comments

@gabrieltrita
Copy link

Environment

  • Ember Version: 3.20.2
  • Ember CLI Version: 3.20.2
  • Ember CP Validations Version: 4.0.0-beta.10
  • Typescript: 4.5.4

Steps to Reproduce

Hello everyone! I'm using native class in my project and we're migrating to Typescript. We have models like this in the current project:

const Validations = buildValidations({
  name: [
    validator('presence', true),
  ]
});

export default class UserModel extends Model.extend(Validations) {
...
}

when changing to typescript the Model.extend(Validations) stops working. Does anyone have an alternative? I've seen decorators like hasValidations implemented in the past, but it's been removed. I wanted to know if we have any alternative for the typescript. Thanks!

@csprocket777
Copy link

We are setting up a validated model first as an extension of the base ember-data model class, and then extending that extension, like this:

const ValidatedBaseModel = BaseModel.extend(Validations) as typeof Model;

export default class SeedModel extends ValidatedBaseModel {

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

No branches or pull requests

2 participants