1
我试图将一个静态方法添加到我的模型,但如果我这样做,我得到这个错误:An interface may only extend a class or another interface.
使用typescript&mongoose的静态方法会:“一个接口只能扩展一个类或另一个接口。”
这是我的代码:
import * as mongoose from 'mongoose';
import {IPermission} from './IPermission';
export interface IRoleDocument extends mongoose.Document {
name: string,
inherit_from: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Role'
},
permissions: Array<IPermission>
};
export interface IRole extends mongoose.Model<IRoleDocument> {
};
错误来自export interface IRole extends mongoose.Model<IRoleDocument>
格尔茨
我读了SA的线程。但是没有静态方法的声明。如果我在你的例子中做了IRoleDefinition定义,但是不是静态的。对于TypeScript,IRoleDocument中的成员不存在。 – R3Tech
我不是猫鼬的专家。为了帮助我,我想澄清以下几点:1)接口不能同时声明静态和实例方法 - 通常使用两个单独的接口2)不可能扩展mongoose.Model,因为它是交叉类型。 –
Amid
我googled如何创建静态方法,打字稿找到和我写的方式是答案......也许是一种堕落的方式。我知道接口只能有一种方法类型,但是如何告诉打字稿我的意思是?第二点,我不清楚...... – R3Tech