从接口排除扩展属性

时间:2019-02-23 09:30:58

标签: typescript

我有一个Contact接口,它扩展了mongoose.Document接口:

import * as mongoose from 'mongoose';

export interface Contact extends mongoose.Document {
    firstname: string;
    lastname: string;
    address: string;
    phone: string;
    email: string;
}

有时,我需要像下面这样使用此接口Contact

const contacts: Contact[] = [
    {
        firstname: 'Marley',
        lastname: 'Schultz',
        address: '531 Walter Roads',
        phone: '1-898-444-3407 x33699'
        email: 'Deon_Hammes@gmail.com',
    }
];

由于Contact扩展了mongoose.Document,TypeScript抱怨mongoose.Document的属性(incrementmodelisDeleted,...)丢失了。

是否可以从Contact获取类型,但排除mongoose.Document的属性?

0 个答案:

没有答案