0
export type MessageGroups = {
    [id: string]: MessageGroupModel
};

export interface MessageGroupModel {
    groupId: string;
    memberIds: string[];
    messages: ChatMessageModel[];
}

Usage is like this:

async handleFullMessageGroupUpdate(newMessageGroup: MessageGroupModel) {
    let messageGroups: MessageGroups = await this.storage.get(StorageKeys.MESSAGES);
    if (!messageGroups) {
      messageGroups = {}
    }
    if (!messageGroups[newMessageGroup.groupId]) {
      messageGroups[newMessageGroup.groupId] = newMessageGroup;
    } else {
      messageGroups[newMessageGroup.groupId].memberIds = newMessageGroup.memberIds;
      messageGroups[newMessageGroup.groupId].memberProfiles = newMessageGroup.memberProfiles;
      messageGroups = this.mergeNewGroupMessages(messageGroups,
        newMessageGroup.messages, newMessageGroup.groupId, newMessageGroup.lastMessageUpdateTime);
    }   
  }

export type MessageGroups declaration is not clear to me. can't I use interface here instead of type?

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • You can indeed use `interface` here instead of `type` - the two can often be interchanged with each other. See https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types – Peter Olson Oct 16 '19 at 17:38
  • @PeterOlson Yes, I saw that. Since I know `interface` well I would like to use it here. Will I miss something here if I'll use the `interface`? Do I need to change any `usage` code then? – Sampath Oct 16 '19 at 17:45
  • As far as I can tell, nothing important will change if you use an `interface` instead. – Peter Olson Oct 16 '19 at 17:47
  • @PeterOlson Thanks for the clarifications. I hope you can put it as an answer. – Sampath Oct 16 '19 at 17:50
  • They are similar in this case but they have significant differences – Aluan Haddad Oct 16 '19 at 19:05

0 Answers0