我正在使用sequelize-typescript
,我的代码是:
import Promise from "bluebird";
import { IncomingCall } from '../models/IncomingCall';
export function incoming(requestBody: object): Promise<IncomingCall> {
return IncomingCall.create({
CallSid: requestBody.CallSid
});
}
但是我得到的错误是:
[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.
我的IncomingCall
是:
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;
}
如何使它正常工作?
答案 0 :(得分:0)
export class IncomingCall extends Model<IncomingCall>
似乎不正确,因为您为类型参数分配了定义时不存在的类型。我想像export class IncomingCall extends Model<{ Callsid: string; AccountsId: string; rawData: string; }>
之类的东西更好,或者您可以在另一个界面中完全定义模型的形状。
答案 1 :(得分:0)
简单的解决方法是更改为:
export function incoming(requestBody: object): Promise<any> {