Skip to content

Use separate types instead of generic types #181

Open
@brichet

Description

@brichet

Generic types can cause a lot of complex TypeScript errors that are difficult to resolve, so I recommend we avoid them unless they are necessary. This seems equivalent & easier to maintain:

interface IBaseChatMessage {
  type: 'msg';
  body: string;
  id: string;
  time: number;
  sender: unknown;
  attachments?: unknown[];
}

/**
 * The interface of a chat message in the chat model.
 */
export interface IChatMessage extends IBaseChatMessage {
  sender: IUser;
  attachments?: IAttachment[];
}

/**
 * The interface of a chat message in the YChat shared document.
 */
export interface IYMessage extends IBaseChatMessage {
  sender: string;
  attachments?: string[];
}

Originally posted by @dlqqq in #148 (comment)

For the context, this would be in replacement of the IChatMessage interface and the IYMessage interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions