profile
viewpoint

Ask questionsType '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[];
}
RobinBuschmann/sequelize-typescript

Answer questions eole1712

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

useful!
source:https://uonfu.com/
Github User Rank List