Why does my Sequelize / Typescript function error with "Two different types with this name exist, but they are unrelated."?

Viewed 702

I'm using sequelize-typescript, and my code is:

import Promise from "bluebird";
import { IncomingCall } from '../models/IncomingCall';
export function incoming(requestBody: object): Promise<IncomingCall> {
  return IncomingCall.create({
    CallSid: requestBody.CallSid
  });
}

But the error I get is:

[ts]
Type 'Bluebird<import("/src/models/IncomingCall").IncomingCall>' is not assignable to type 'Bluebird<import("/src/models/IncomingCall").IncomingCall>'. Two different types with this name exist, but they are unrelated.
  Types of property 'then' are incompatible.

My IncomingCall is:

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

@Table
export class IncomingCall extends Model<IncomingCall> {

  @Column
  CallSid: string;

  @Column
  AccountSid: string;

  @Column(DataType.JSON)
  rawData: string;

}

How do I get this to work properly?

2 Answers

export class IncomingCall extends Model<IncomingCall> seems incorrect as you assign to a type parameter a type that does not exist at definition time. I guess something like export class IncomingCall extends Model<{ Callsid: string; AccountsId: string; rawData: string; }> is better, or you could define the shape of your model in another interface altogether.

Simple fix was to change to:

export function incoming(requestBody: object): Promise<any> {
Related