sequelize / sequelize-typescript

Decorators and some other features for sequelize
MIT License
2.79k stars 282 forks source link

all where conditions in include array for scopes decorator seem enforce same schemas? #838

Open davidxiaolux opened 4 years ago

davidxiaolux commented 4 years ago

Probably sequelize issue, but it seems compatibility issue for sequelize/sequelize-typescript

Versions

I'm submitting a ...

[x] bug report [ ] feature request

Actual behavior:

For decorator scopes, all where conditions in include array seem enforce the same schema somehow? https://github.com/davidxiaolux/sequelize-typescript-example/blob/master/lib/models/Person.ts#L23

Expected behavior:

should be no issue for include array with different conditions in where

Steps to reproduce: just open file https://github.com/davidxiaolux/sequelize-typescript-example/blob/master/lib/models/Person.ts#L23 via editor, like VS Code, it will give error indication.

` {

"resource": "~/sequelize/src/models/person.ts",

"owner": "typescript",
"code": "2769",
"severity": 8,
"message": "No overload matches this call.\n  Overload 1 of 2, '(scopesGetter: ScopesOptionsGetter): Function', gave the following error.
Type '({ model: typeof Post; required: true; where: { isDeleted: false; postCode?: undefined; }; order: Col; separate?: undefined; } | { model: typeof Address; required: true; separate: true; where: { ...; }; order?: undefined; })[]' is not assignable to type 'Includeable[]'.
 Type '{ model: typeof Post; required: true; where: { isDeleted: false; postCode?: undefined; }; order: Col; separate?: undefined; } | { model: typeof Address; required: true; separate: true; where: { ...; }; order?: undefined; }' is not assignable to type 'Includeable'.
Type '{ model: typeof Post; required: true; where: { isDeleted: false; postCode?: undefined; }; order: Col; separate?: undefined; }' is not assignable to type 'Includeable'.

Type '{ model: typeof Post; required: true; where: { isDeleted: false; postCode?: undefined; }; order: Col; separate?: undefined; }' is not assignable to type 'IncludeOptions'. Types of property 'where' are incompatible. Type '{ isDeleted: false; postCode?: undefined; }' is not assignable to type 'WhereAttributeHash | AndOperator | OrOperator | Literal | Where | undefined'. Type '{ isDeleted: false; postCode?: undefined; }' is not assignable to type 'WhereAttributeHash'. Property 'postCode' is incompatible with index signature. Type 'undefined' is not assignable to type 'string | number | boolean | WhereAttributeHash | AndOperator | OrOperator | Literal | Where | WhereOperators | ... 4 more ... | null'. Overload 2 of 2, '(scopes: ScopeTableOptions): Function', gave the following error. Argument of type '() => { resources: { where: { isDeleted: false; }; include: ({ model: typeof Post; required: true; where: { isDeleted: false; postCode?: undefined; }; order: Col; separate?: undefined; } | { model: typeof Address; required: true; separate: true; where: { ...; }; order?: undefined; })[]; }; }' is not assignable to parameter of type 'ScopeTableOptions'.\n Index signature is missing in type '() => { resources: { where: { isDeleted: false; }; include: ({ model: typeof Post; required: true; where: { isDeleted: false; postCode?: undefined; }; order: Col; separate?: undefined; } | { model: typeof Address; required: true; separate: true; where: { ...; }; order?: undefined; })[]; }; }'.", "source": "ts", "startLineNumber": 20, "startColumn": 2, "endLineNumber": 39, "endColumn": 2 }`

meaning wheres in

https://github.com/davidxiaolux/sequelize-typescript-example/blob/master/lib/models/Person.ts#L27 and

https://github.com/davidxiaolux/sequelize-typescript-example/blob/master/lib/models/Person.ts#L34 should follow the exact schema?

davidxiaolux commented 4 years ago

different where conditions for type(https://github.com/sequelize/sequelize/blob/v5.22.0/types/lib/model.d.ts#L371) should allow different schema, but it complains it should be the same across all where conditions,