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

Support for Sequelize v6 #804

Closed
AuHau opened this issue Jun 26, 2020 · 19 comments
Closed

Support for Sequelize v6 #804

AuHau opened this issue Jun 26, 2020 · 19 comments

Comments

@AuHau
Copy link

AuHau commented Jun 26, 2020

Versions

  • sequelize: 6.2.0
  • sequelize-typescript: 1.1.0
  • typescript: 3.9.5

I'm submitting a ...

[x] bug report
[ ] feature request

Details:

There is a new major Sequelize release v6 that changes Sequelize's internals quite a bit (for example removing Bluebird, yey!)

These are the types errors that I get running it against this version:


node_modules/sequelize-typescript/dist/associations/belongs-to-many/belongs-to-many-association.d.ts:12:5 - error TS2416: Property 'getSequelizeOptions' in type 'BelongsToManyAssociation' is not assignable to the same property in base type 'BaseAssociation'.
  Type '(model: typeof import(".../node_modules/sequelize/types/lib/model").Model, sequelize: import(".../node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize").Sequelize) => import(".../node_modules/sequeli...' is not assignable to type '(model: typeof import(".../node_modules/sequelize-typescript/dist/model/model/model").Model, sequelize: import(".../node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize").Sequelize) => import(".../no...'.
    Types of parameters 'model' and 'model' are incompatible.
      Type 'typeof import(".../node_modules/sequelize-typescript/dist/model/model/model").Model' is not assignable to type 'typeof import(".../node_modules/sequelize/types/lib/model").Model'.
        Types of property 'init' are incompatible.
          Type '(attributes: ModelAttributes<Model<any, any>, any>, options: InitOptions<Model<any, any>>) => void' is not assignable to type '<M extends Model<any, any>>(this: ModelStatic<M>, attributes: ModelAttributes<M, M["_creationAttributes"]>, options: InitOptions<M>) => Model<...>'.

12     getSequelizeOptions(model: typeof Model, sequelize: Sequelize): UnionAssociationOptions;
       ~~~~~~~~~~~~~~~~~~~

node_modules/sequelize-typescript/dist/associations/has/has-association.d.ts:11:5 - error TS2416: Property 'getSequelizeOptions' in type 'HasAssociation' is not assignable to the same property in base type 'BaseAssociation'.
  Type '(model: typeof Model) => UnionAssociationOptions' is not assignable to type '(model: typeof Model, sequelize: Sequelize) => UnionAssociationOptions'.
    Types of parameters 'model' and 'model' are incompatible.
      Type 'typeof import(".../node_modules/sequelize-typescript/dist/model/model/model").Model' is not assignable to type 'typeof import(".../node_modules/sequelize/types/lib/model").Model'.

11     getSequelizeOptions(model: typeof Model): UnionAssociationOptions;
       ~~~~~~~~~~~~~~~~~~~

node_modules/sequelize-typescript/dist/model/model/model.d.ts:1:89 - error TS2305: Module '"../../../../sequelize/types"' has no exported member 'Promise'.

1 import { InitOptions, Model as OriginModel, ModelAttributes, FindOptions, BuildOptions, Promise } from 'sequelize';
                                                                                          ~~~~~~~

node_modules/sequelize-typescript/dist/model/model/model.d.ts:9:31 - error TS2417: Class static side 'typeof import(".../node_modules/sequelize-typescript/dist/model/model/model").Model' incorrectly extends base class static side 'typeof import(".../node_modules/sequelize/types/lib/model").Model'.
  The types returned by 'init(...)' are incompatible between these types.
    Type 'void' is not assignable to type 'Model<any, any>'.

9 export declare abstract class Model<T = any, T2 = any> extends OriginModel<T, T2> {
                                ~~~~~

node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize.d.ts:12:5 - error TS2416: Property 'model' in type 'Sequelize' is not assignable to the same property in base type 'Sequelize'.
  Type '(model: string | typeof Model) => ModelCtor<Model<any, any>>' is not assignable to type '(modelName: string) => ModelCtor<Model<any, any>>'.
    Type 'import(".../node_modules/sequelize-typescript/dist/model/model/model").ModelCtor<import(".../node_modules/sequelize-typescript/dist/model/model/model").Model<any, any>>' is not assignable to type 'import(".../node_modules/sequelize/types/lib/model").ModelCtor<import(".../node_modules/sequelize/types/lib/model").Model<any, any>>'.
      Type 'ModelCtor<Model<any, any>>' is not assignable to type 'typeof Model'.
        The types returned by 'init(...)' are incompatible between these types.
          Type 'void' is not assignable to type 'Model<any, any>'.

12     model(model: string | typeof Model): ModelCtor;
       ~~~~~

src/cli.ts:75:21 - error TS2345: Argument of type 'import(".../node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize").Sequelize' is not assignable to parameter of type 'import(".../node_modules/sequelize/types/lib/sequelize").Sequelize'.
  The types returned by 'model(...)' are incompatible between these types.
    Type 'import(".../node_modules/sequelize-typescript/dist/model/model/model").ModelCtor<import(".../node_modules/sequelize-typescript/dist/model/model/model").Model<any, any>>' is not assignable to type 'import(".../node_modules/sequelize/types/lib/model").ModelCtor<import(".../node_modules/sequelize/types/lib/model").Model<any, any>>'.
      Type 'ModelCtor<Model<any, any>>' is not assignable to type 'typeof Model'.

75     await initStore(sequelize)
                       ~~~~~~~~~


Found 6 errors.
@ShaharHD
Copy link

#787 should resolve this

@sarfarazansari
Copy link

any idea how to fix this

@Jaspaul
Copy link

Jaspaul commented Jul 3, 2020

@sarfarazansari I'm currently working around this by using v5 of sequelize.

@IrakliDevelop
Copy link

Any progress on this issue?

@Bialogs
Copy link

Bialogs commented Oct 15, 2020

For what its worth, I am still having issues with 2.0.0-beta.0 and sequelize 6.3.5

@lukashroch
Copy link
Collaborator

lukashroch commented Dec 10, 2020

@Bialogs can you try recent 2.0.0-beta.1?

@rbclark
Copy link

rbclark commented Dec 14, 2020

@lukashroch I'm working with @Bialogs on this one, just tried with the latest 2.0.0-beta.1 and still received type errors.

Details
    src/evaluation-tags/evaluation-tag.model.ts:38:21 - error TS2322: Type 'typeof Evaluation' is not assignable to type 'typeof Model'.
      Types of construct signatures are incompatible.
        Type 'new (values?: Evaluation | undefined, options?: BuildOptions | undefined) => Evaluation' is not assignable to type 'new <TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes>(values?: TCreationAttributes | undefined, options?: BuildOptions | undefined) => Model<TModelAttributes, TCreationAttributes>'.
          Types of parameters 'values' and 'values' are incompatible.
            Type 'TCreationAttributes | undefined' is not assignable to type 'Evaluation | undefined'.
              Type 'TCreationAttributes' is not assignable to type 'Evaluation | undefined'.
                Type '{}' is not assignable to type 'Evaluation'.
                  Type 'TCreationAttributes' is not assignable to type 'Evaluation'.
                    Type '{}' is missing the following properties from type 'Evaluation': id, filename, data, createdAt, and 38 more.

    38   @ForeignKey(() => Evaluation)
                           ~~~~~~~~~~

      ../../node_modules/sequelize-typescript/dist/model/shared/model-class-getter.d.ts:2:40
        2 export declare type ModelClassGetter = (returns?: void) => typeof Model;
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        The expected type comes from the return type of this signature.
    src/evaluation-tags/evaluation-tag.model.ts:42:20 - error TS2769: No overload matches this call.
      Overload 1 of 2, '(associatedClassGetter: ModelClassGetter, foreignKey?: string | undefined): Function', gave the following error.
        Type 'typeof Evaluation' is not assignable to type 'typeof Model'.
      Overload 2 of 2, '(associatedClassGetter: ModelClassGetter, options?: BelongsToOptions | undefined): Function', gave the following error.
        Type 'typeof Evaluation' is not assignable to type 'typeof Model'.

    42   @BelongsTo(() => Evaluation)
                          ~~~~~~~~~~

      ../../node_modules/sequelize-typescript/dist/model/shared/model-class-getter.d.ts:2:40
        2 export declare type ModelClassGetter = (returns?: void) => typeof Model;
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        The expected type comes from the return type of this signature.
      ../../node_modules/sequelize-typescript/dist/model/shared/model-class-getter.d.ts:2:40
        2 export declare type ModelClassGetter = (returns?: void) => typeof Model;
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        The expected type comes from the return type of this signature.

 FAIL  test/evaluations.e2e-spec.ts
  ● Test suite failed to run

    src/evaluations/evaluation.model.ts:41:18 - error TS2769: No overload matches this call.
      Overload 1 of 2, '(associatedClassGetter: ModelClassGetter, foreignKey?: string | undefined): Function', gave the following error.
        Type 'typeof EvaluationTag' is not assignable to type 'typeof Model'.
          Types of construct signatures are incompatible.
            Type 'new (values?: EvaluationTag | undefined, options?: BuildOptions | undefined) => EvaluationTag' is not assignable to type 'new <TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes>(values?: TCreationAttributes | undefined, options?: BuildOptions | undefined) => Model<TModelAttributes, TCreationAttributes>'.
              Types of parameters 'values' and 'values' are incompatible.
                Type 'TCreationAttributes | undefined' is not assignable to type 'EvaluationTag | undefined'.
                  Type 'TCreationAttributes' is not assignable to type 'EvaluationTag | undefined'.
                    Type '{}' is not assignable to type 'EvaluationTag'.
                      Type 'TCreationAttributes' is not assignable to type 'EvaluationTag'.
                        Type '{}' is missing the following properties from type 'EvaluationTag': id, key, value, createdAt, and 39 more.
      Overload 2 of 2, '(associatedClassGetter: ModelClassGetter, options?: HasManyOptions | undefined): Function', gave the following error.
        Type 'typeof EvaluationTag' is not assignable to type 'typeof Model'.

    41   @HasMany(() => EvaluationTag)
                        ~~~~~~~~~~~~~

      ../../node_modules/sequelize-typescript/dist/model/shared/model-class-getter.d.ts:2:40
        2 export declare type ModelClassGetter = (returns?: void) => typeof Model;
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        The expected type comes from the return type of this signature.
      ../../node_modules/sequelize-typescript/dist/model/shared/model-class-getter.d.ts:2:40
        2 export declare type ModelClassGetter = (returns?: void) => typeof Model;
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        The expected type comes from the return type of this signature.

 FAIL  test/authn.e2e-spec.ts
  ● Test suite failed to run

    src/evaluation-tags/evaluation-tags.service.ts:53:30 - error TS2345: Argument of type 'CreateEvaluationTagDto' is not assignable to parameter of type 'EvaluationTag'.
      Type 'CreateEvaluationTagDto' is missing the following properties from type 'EvaluationTag': id, createdAt, updatedAt, evaluationId, and 37 more.

    53     return new EvaluationTag(createEvaluationTagDto);

@chorfa007
Copy link

Hello,

The same for me i'm getting this error with the below config
"sequelize": "^6.3.5s",
"sequelize-typescript": "^1.1.0"

@lukashroch
Copy link
Collaborator

@rbclark, check out #865, there is a breaking change how to define models for V6. This is also described in official sequlize TS docs section.

@chorfa007, use 2.0.0-beta.1 for V6, 1.1.0 is V5 only and follow link above how to upgrade.

@niloyc
Copy link

niloyc commented Dec 28, 2020

@lukashroch Typeerrors are still ocurring, I literally copied and pasted the model code from the docs you linked alongside 2.0.0-beta.1 & 6.3.5

No overload matches this call.
  The last overload gave the following error.
    Type 'typeof Person' is not assignable to type 'string | ModelCtor<Model<any, any>>'.
      Type 'typeof Person' is not assignable to type 'ModelCtor<Model<any, any>>'.
        Type 'typeof Person' is not assignable to type 'typeof Model'.
          Types of construct signatures are incompatible.
            Type 'new (values?: PersonCreationAttributes, options?: BuildOptions) => Person' is not assignable to type 'new <TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes>(values?: TCreationAttributes, options?: BuildOptions) => Model<TModelAttributes, TCreationAttributes>'.
              Types of parameters 'values' and 'values' are incompatible.
                Type 'TCreationAttributes' is not assignable to type 'PersonCreationAttributes'.
                  Property 'name' is missing in type '{}' but required in type 'PersonCreationAttributes'.ts(2769)

@lukashroch
Copy link
Collaborator

lukashroch commented Dec 28, 2020

@niloyc I've only thoroughly tested "less strict" typings, which are the same equivalent of what already was present in v5 or < v6.2. I've already encountered other weird issues with new v6.2+ typings, looks like they will need more tweaking, so I left it for a while... Though, just converted one of our project with minimal effort to less-strict types and so far no issues.

Looks like #868 PR is addressing some of these issues you're having. You could give it a try and review.

@axayi
Copy link

axayi commented Jan 11, 2021

I am trying log custom exception in angular using TS but not catch block is not executing getting following error
i have implemented handleError() Method - where custom exception messages are available

LoadList(): Observable<ABC[]> {
return this.http.get<ABC[]>(this.apiUrl).pipe(
retry(1),
catchError(this.handleError)

//  //catchError((error: any) => {
//  //  return this.handleerror; //observable.throw(new error(error));
//  //})

}

i am getting below error and catch block is not working

image

@theoludwig
Copy link
Contributor

[email protected] has been released! 😄
Feel free to open new issues, if you encounter bugs! 🐛

@kuriel-trivu
Copy link

kuriel-trivu commented Mar 18, 2021

This versions aren't compatible:
"sequelize": "6.5.1",
"sequelize-typescript": "2.1.0",

@deviantfero
Copy link

deviantfero commented May 25, 2021

I'm having issues with this too:

    "sequelize": "^6.6.2",
    "sequelize-typescript": "^2.1.0",
    "@nestjs/sequelize": "^0.2.0",

EDIT:

For anyone trying to fix this, I was coming from sequelize v5 and sequelize-typescript 1.1.0 when I upgraded I did the following to solve the type errors I was having:

previously:

export class User extends Model<User> {

turns to just:

export class User extends Model {

thanks for this awesome library 🎉

@kuriel-trivu
Copy link

I'm having issues with this too:

    "sequelize": "^6.6.2",
    "sequelize-typescript": "^2.1.0",
    "@nestjs/sequelize": "^0.2.0",

EDIT:

For anyone trying to fix this, I was coming from sequelize v5 and sequelize-typescript 1.1.0 when I upgraded I did the following to solve the type errors I was having:

previously:

export class User extends Model<User> {

turns to just:

export class User extends Model {

thanks for this awesome library 🎉

I gonna give a try.

@kuriel-trivu
Copy link

@deviantfero it worked 🎉🎉🎉

I have like 100 entities, no joke, it was epic easy but tedious, but it worked!!

i have updated the library, yay!

image

@deviantfero
Copy link

@kuriel-trivu that's great, if someone could explain why this works that would be really helpful though 😅, I don't want to find out I'm missing some type declaration correctness down the line

@daniloftorres
Copy link

"@nestjs/sequelize": "^0.2.0",
"sequelize": "^6.6.2",
"sequelize-typescript": "^2.1.0"

worked for me

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