Solvedsequelize typescript Type 'typeof Player' is not assignable to type 'typeof Model'

Versions

  • sequelize: sequelize@6.3.5
  • sequelize-typescript: sequelize-typescript@1.1.0
  • typescrip: typescript@4.0.2

I'm submitting a ...

[X] bug report
[ ] feature request

Actual behavior:
I have added 2 class files, Player.ts and Team.ts as per the example. In each of the references:

  @HasMany(() => Player)

and

  @ForeignKey(() => Team)
  @Column
  teamId: number;
 
  @BelongsTo(() => Team)
  team: Team;

The Team and the Player following the => on the attribute is underlines in red in VS code with the error:

Type 'typeof Team' is not assignable to type 'typeof Model'.
  Construct signature return types 'Team' and 'Model<T, T2>' are incompatible.
    The types of '_attributes' are incompatible between these types.
      Type 'Team' is not assignable to type 'T'.
        'T' could be instantiated with an arbitrary type which could be unrelated to 'Team'.ts(2322)
model-class-getter.d.ts(2, 40): The expected type comes from the return type of this signature.

Expected behavior:
No Errors

Steps to reproduce:
Added Player.ts with the sample code provided in the readme.md, and Team.ts in the same way

Related code:
Player.ts

import { Table, Model, Column, ForeignKey, BelongsTo } from 'sequelize-typescript'

@Table
export class Player extends Model<Player> {
 
  @Column
  name: string;
 
  @Column
  num: number;
 
  @ForeignKey(() => Team)
  @Column
  teamId: number;
 
  @BelongsTo(() => Team)
  team: Team;
}

Team.ts

import { Table, Model, Column, ForeignKey, HasMany } from 'sequelize-typescript'
import { Player } from './Player';


@Table
export class Team extends Model<Team> {
 
  @Column
  name: string;
 
  @HasMany(() => Player)
  players: Player[];
}
20 Answers

✔️Accepted Answer

You can use sequelize^6.3.5 + sequelize-typescript^2.0.0-beta.1, you only need to remove argument from Model<...>:

-export class Team extends Model<Team> {
+export class Team extends Model {

Thanks to @lukashroch for updated docs: https://github.com/lukashroch/sequelize-typescript/tree/sequelize6-docs#v6-model-definition-less-strict

Other Answers:

It's related to sequelize@6.3.5. I have the same issue with both sequelize-typescript @1.1.0 & @2.0.0-beta.0

If I downgrade to sequelize@5.22.0 the issue is gone.

It must be a change in the sequelize Model type which is not compatible with the decorators typing.

Already reported in: #828, #826, #821 #813

Looks like using sequelize@6.1.1 solve the issue for now, which is the last version of sequelize with Model type compatible with sequelize-typescript.

I have the same problem with

"sequelize": "^6.3.5",
"sequelize-typescript": "^2.0.0-beta.0"

and

"sequelize": "^6.1.1",
"sequelize-typescript": "^2.0.0-beta.0"

resolved with downgrade to

"sequelize": "^5.22.0",
"sequelize-typescript": "^1.1.0"

Thanks your proposal can solve the issue

Hello @Austine105, did you found any solution for this issue ? I have the same problem with nest.js

Same here, @RobinBuschmann any idea what's going on?

Related Issues:

18
sequelize typescript Type 'typeof Player' is not assignable to type 'typeof Model'
You can use sequelize^6.3.5 + sequelize-typescript^2.0.0-beta.1 Versions sequelize: sequelize@6.3.5 ...
11
sequelize typescript Sequelize v5.13.0 not supported
Hey @justinlottes thanks for reporting Just published a new beta version (sequelize-typescript@1.0.0...
5
sequelize typescript Problems with multiple relationships
Hey @Dragons0458 your setup is totally fine The issue is the query itself Hi! ...
98
labelImg labelImg 1.5.2 on windows crashed
Just delete the file .labelImgSettings.pkl which is locate at C:\\Users\your_account\ Then reopen La...
92
labelImg Question: how to fix "ModuleNotFoundError: No module named 'libs.resources' "
Thx v much for that reference The following band-aid from that issue fixed for me: pyrcc5 -o libs/re...
52
swag cannot find type definition: gorm.Model
I am having the same issue: 2020/10/28 13:52:34 ParseComment error in file **/file/path/.go :cannot ...
46
swag Version 1.6.9 - cannot find type definition
For those who need a quick solution: go get -u github.com/swaggo/swag/cmd/swag@v1.6.7 ...
12
cvat Unable to remote connect
To help anyone out there with complete solution: Create in cvat home directory file docker-compose.o...
8
labelImg Cannot install on macOS High Sierra if I use qt4 and make qt4py2
This worked for me on OSX High Sierra: Hello guys.Just to let you know that the installation for mac...
8
labelme Unable to save: 'bytes' object has no attribute 'encode'
I tested in this way on windows and it worked In labelFile.py def save(...): with open(filename ...
3
label studio Encoding
@makseq I installed Label Studio with your realease/0.7.4 branch with the command : pip install --up...
101
type graphql Getting "Schema must contain uniquely named types but contains multiple types named" for a single type
This was a hard one to track down with an annoying fix (Nest specific not the fault of type-graphql)...
76
vue property decorator Property 'title' has no initializer and is not definitely assigned in the constructor.
Since you use the latest version of TS you mention the error Please see the section Strict Class Ini...
47
type graphql Cannot determine GraphQL input type for
For future readers This may have been due to using an @ObjectType() CompanyData as an @InputType() i...
28
type graphql Integration with Prisma
Hi @19majkel94! We're still very interested in supporting you with a seamless Prisma integration Giv...
12
class validator feat: add option to stop validation after first validation error
I agree Would be much efficient when no validators would run after one failed My example: IsInModel ...
5
type graphql Error when using GraphQLJSON
@darkmantle Setting: Means you should use default import: The latest version (0.15.0) seems to have ...
375
laravel mongodb Composer can't find mongodb extension
composer require jenssegers/mongodb --ignore-platform-reqs It solved my problem. ...
320
sequelize Class constructor Model cannot be invoked without 'new' and how getter v4 work?
Intypescript case my solution was to change target from es5 to es6 Hi all ...
161
typeorm Error: RepositoryNotFoundError: No repository for [Enitity] was found. Looks like this entity is not registered in current "default" connection?
https://typeorm.io/#/connection-options/common-connection-options Issue type: [x] question [x] bug r...
130
prisma Prisma Migrate: Error creating shadow database
I just want to add a quick note for folks coming here from googling the error message that if you ar...
129
sequelize Sequelize intellisense doesn't work in Visual Studio Code
This looks like a bug with VSCode to be honest.. I just tried to reproduce What are you doing? I ins...
124
efcore No executable found matching command "dotnet-ef" even after adding CLI
I has this issue and like to share I want to Migrate my Database with Models I am using EF Core 2.0 ...
118
sequelize TimeoutError: ResourceRequest timed out
I have fixed the issue by maximizing the acquire option of pool configuration in sequelize I guess A...
117
diesel Could not compile diesel_cli
i install and it works Thanks Guys! Setup Versions Rust: rustc 1.33.0 (2aa4c46cf 2019-02-28) Databas...
116
efcore UseSqlServer() method is missing from Microsoft.EntityFrameworkCore.SqlServer 1.1.1
Hm - try manually adding the using statement using Microsoft.EntityFrameworkCore; and building again...
87
sequelize Using underscored: true still returns attributes in camelCase
Hello I was having the same problem as @twistedrc1017 with the timestamps created_ at and updated_at...
78
typeorm Relation decorators: allow to pass string instead of typeFunction
PR is submitted As an example Issue type: [ ] question [ ] bug report [x] feature request [ ] docume...
77
sequelize 4.0 Model definition syntax
After all night of tweaking I finally have a working example based on @leebenson and @felixfbecker's...
76
typeorm How to get foreign key for instance?
You can't do that because your group is relation object its not a simple number (id of the pricetagg...
71
typeorm MissingDriverError: Wrong driver: "undefined" given.
solved it by export the config this way in my ormconfig.ts: Issue type: [ ] question [X] bug report ...
65
sequelize Class constructor Model cannot be invoked without 'new'
@SimonSchick Interesting I didn't know that Indeed adding the following tsconfig.json to my root fol...
65
sequelize Please install mysql2 package manually
@arielrahmane wherever you import sequelize you can set the dialectModule in the options Example bel...
64
typeorm .save() is throwing duplicate key value violates unique constraint
I can confirm that this problem still exists I'm using typeorm with postgres. Issue type: [x] questi...
64
typeorm Error: Entity metadata was not found
I ran into the same issue TypeORM is very difficult to debug with args and meta data classes/collect...
63
sequelize Separate: true — Cannot read property 'push' of undefined
I got to make it work on my side by specifying the foreignKey in the included attributes I'm using s...
62
typeorm WHERE, Date, and BETWEEN
It appears that there is a bug with how QueryBuilder is handling dates I only tested with SQLite ...
60
efcore How to write DbFunction's translation?
@Kation You actually does not need so much of code to use JSON_VALUE function Based on documentation...
58
efcore Inheritance problem with DbContext subclasses requiring constructor to supply DbContextOptions<DerivedContext>
I was able to resolve this without a hack by providing a protected constructor that uses DbContextOp...
56
typeorm ER_NOT_SUPPORTED_AUTH_MODE after upgrade
I found a solution for docker --default-authentication-plugin=mysql_native_password ...
51
prisma1 Nested upsert in create mutations (correct: nested connectOrCreate)
We are thinking about implementing this soon Feature Request What feature are you missing? A nested ...
50
efcore MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences
@AmSmart just to clarify in the documentation that @ajcvickers mentioned it gives updated code for t...
49
sequelize Error in sequelize.import: defineCall is not a function
That means you have tried to import a module that did not do a module.exports = function() { ...
48
typeorm { EntityMetadataNotFound: No metadata for "User" was found.
In my case I just needed to change this : Into this : Hello I'm trying to setup a new project using ...
47
diesel Installing diesel_cli on Windows : some assembly required
I think the best way to address this issue now is following these instructions: If you are using a s...
47
ef6 cannot bind argument to parameter 'path' because it is null
I realize that this issue is closed but I too have started seeing this issue and thought this might ...
47
efcore error NU1202: Package dotnet-ef 3.0.1 is not compatible with netcoreapp3.0
@bricelam Presumably the workaround for anyone hitting this is to install the 3.0.0 version explicit...
44
typeorm Migration cli unexpected token import
Anyone wondering about this you must run your .ts files thru ts-node first Simply: ...
44
typeorm ts-node throwing RepositoryNotFoundError
I also had the same No repository for .. in current default connection and it worked fine for develo...
43
typeorm many-to-many-relations with not default join table columns names
@DavidBM can you please provide a more detailed description of the issue you have and what you are t...