Sequelize-typescript: Support for Sequelize v6

Created on 26 Jun 2020  ·  14Comments  ·  Source: RobinBuschmann/sequelize-typescript

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.

Most helpful comment

Any progress on this issue?

All 14 comments

787 should resolve this

any idea how to fix this

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

Any progress on this issue?

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

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

@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);

Hello,

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

@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.

@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)

@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.

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 return this.http.get 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

[email protected] has been released! :smile:
Feel free to open new issues, if you encounter bugs! :bug:

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fareshan picture fareshan  ·  3Comments

lverledens picture lverledens  ·  4Comments

lilling picture lilling  ·  4Comments

CampaUTN picture CampaUTN  ·  4Comments

JustGreg picture JustGreg  ·  4Comments