Skip to content

Error casting SequelizeStaticAndInstance.Model to Model #20

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

Closed
louy opened this issue Jul 17, 2016 · 1 comment
Closed

Error casting SequelizeStaticAndInstance.Model to Model #20

louy opened this issue Jul 17, 2016 · 1 comment
Labels

Comments

@louy
Copy link
Collaborator

louy commented Jul 17, 2016

Reported by @Thylossus in #14.

Changed type of return value of Model<TInstance, TAttributes>.scope from this to Model<TInstance, TAttributes>. The following example in https://github.com/Thylossus/sequelize-pull-request-justification-demo/tree/master tries to mimic the example from https://github.com/louy/typed-sequelize/blob/master/README.md.

However, I cannot compile this example due to a type error:

index.ts(16,16): error TS2322: Type 'sequelize.Model<Thing, ThingInstance>' is not assignable to type 'sequelize.SequelizeStaticAndInstance.Model<Thing, ThingInstance>'.
  Types of property 'scope' are incompatible.
    Type '(options?: string | string[] | ScopeOptions | WhereOptions) => Model<Thing, ThingInstance>' is not assignable to type '(options?: string | string[] | ScopeOptions | WhereOptions) => this'.
      Type 'Model<Thing, ThingInstance>' is not assignable to type 'this'.

This is probably related to microsoft/TypeScript#5863. Changing the return type of scope solves the error for me.
Of course, this is not a sufficient criterion for changing your code, but I believe that isn't working for anyone. Feedback about the correctness of this assumption is very welcome.

@louy louy added the bug label Jul 17, 2016
@louy louy changed the title Error casting sequelize.SequelizeStaticAndInstance.Model to sequelize.Model Error casting SequelizeStaticAndInstance.Model to Model Jul 17, 2016
@louy louy changed the title Error casting SequelizeStaticAndInstance.Model to Model Error casting SequelizeStaticAndInstance.Model to Model Jul 17, 2016
@louy
Copy link
Collaborator Author

louy commented Jul 17, 2016

Interestingly, this only happens if you use import {Model, Instance} from 'sequelize'; instead of import * as Sequelize from 'sequelize';.
My guess is that it has something to do with the way we use export =. Could be related to microsoft/TypeScript#5863 but it's not the same issue.

@louy louy closed this as completed in 5682cca Jul 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant