Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'typeof Questions' is not assignable to type 'typeof Model'

I am getting the error Type 'typeof Questions' is not assignable to type 'typeof Model'. while added the relationship in the model.

question.model.ts

import { Column, Table, PrimaryKey, Default, DataType, Model } from "sequelize-typescript";

@Table({timestamps: true})
export class Questions extends Model<Questions> {

    @PrimaryKey
    @Default(DataType.UUIDV1)
    @Column(DataType.UUID)
    id: string;

    @Column
    question: string;

    @Column({ defaultValue: true })
    isActive: boolean;
}

options.model.ts

import { Column, Table, PrimaryKey, Default, DataType, ForeignKey, HasOne, Model } from "sequelize-typescript";
import { Questions } from "./models/questions.model";

@Table({timestamps: true})
export class Options extends Model<Options> {

    @PrimaryKey
    @Default(DataType.UUIDV1)
    @Column(DataType.UUID)
    id: string;

    @ForeignKey(() => Questions)
    @Column
    questionsId: number;

    @HasOne(() => Questions)
    question: Questions;

    @Column({ defaultValue: false })
    isCorrectAns: boolean;
}

my user module

import { SequelizeModule } from '@nestjs/sequelize';
import { Questions } from './models/questions.model';
import { Options } from './options.model';

@Module({
  imports: [
    SequelizeModule.forFeature([Questions, Options])
  ],
  controllers: [UserController],
  providers: [UserService]
})
export class UserModule {}
like image 654
Aman Kumar Avatar asked Dec 13 '22 08:12

Aman Kumar


1 Answers

I've had this same issue. Could resolve this by removing the type constructor (<Questions>, <Options>).

In my case I had a QuestionsAttributes interface and had to change:

class TalentData extends Model<TalentData, TalentDataAttributes>

to:

class TalentData extends Model implements TalentDataAttributes

But this appears to be a sequelize-typescript error.

like image 57
Gabriel Carvalho Avatar answered Dec 31 '22 10:12

Gabriel Carvalho