how can I get vscode to suggest the key of mainMap, as socketId: string instead of only string?
type SocketId = string;
type User = {displayName: string}
let mainMap = new Map<SocketId, User>();
CodePudding user response:
You can add an intersection with {}. This will not have any impact on assignability, but it will prevent TS form inlining the alias:
type SocketId = string & {};
type User = {displayName: string}
let mainMap = new Map<SocketId, User>();
You might also consider branded types to check that the socket id is valid.
