Skip to content

Type 'typeof Player' is not assignable to type 'typeof Model' #835

Closed
@robpearmain

Description

@robpearmain

Versions

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[];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions