Suppose we have the following:
export enum Relationship {}
export interface Invitee {}
export interface InviteesResponse {
invitees: Invitee[];
relationships: { [key: string]: Relationship }; // mapping userIds to relationships
}
async function getInvitees(userId: string): Promise<InviteesResponse> {
...
const invitees: Invitee[] = [];
const relationships: Map<string, Relationship> = new Map();
...
// this line is where the error occurs with relationships
return { invitees, relationships };
When I consulted Webstorm for a solution, it suggested the following change:
async function getInvitees(userId: string): Promise<{ invitees: Invitee[]; relationships: Map<string, Relationship> }> {
I am struggling to grasp the underlying issue. Why do I need to destructure the type before returning it?
Here's the error message once more:
Type 'Map<string, Relationship>' cannot be assigned to type '{ [key: string]: Relationship; }'. An index signature is missing in type 'Map<string, Relationship>'.