Skip to content

Commit

Permalink
chore: address ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Mar 5, 2024
1 parent cf321a8 commit 74ddb3b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/grpc-js/src/channelz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,26 @@ export type TraceSeverity =
| 'CT_WARNING'
| 'CT_ERROR';

export interface ChannelRef {
kind: EntityTypes.channel;
interface Ref {
kind: EntityTypes;
id: number;
name: string;
}

export interface SubchannelRef {
export interface ChannelRef extends Ref {
kind: EntityTypes.channel;
}

export interface SubchannelRef extends Ref {
kind: EntityTypes.subchannel;
id: number;
name: string;
}

export interface ServerRef {
export interface ServerRef extends Ref {
kind: EntityTypes.server;
id: number;
name: string;
}

export interface SocketRef {
export interface SocketRef extends Ref {
kind: EntityTypes.socket;
id: number;
name: string;
}

function channelRefToMessage(ref: ChannelRef): ChannelRefMessage {
Expand Down Expand Up @@ -361,6 +359,8 @@ export const enum EntityTypes {
socket = 'socket',
}

type EntryOrderedMap = OrderedMap<number, { ref: Ref; getInfo: () => any }>;

const entityMaps = {
[EntityTypes.channel]: new OrderedMap<number, ChannelEntry>(),
[EntityTypes.subchannel]: new OrderedMap<number, SubchannelEntry>(),
Expand Down Expand Up @@ -404,6 +404,8 @@ const generateRegisterFn = <R extends EntityTypes>(kind: R) => {
return nextId++;
}

const entityMap: EntryOrderedMap = entityMaps[kind];

return (
name: string,
getInfo: () => InfoByType<R>,
Expand All @@ -412,8 +414,7 @@ const generateRegisterFn = <R extends EntityTypes>(kind: R) => {
const id = getNextId();
const ref = { id, name, kind } as RefByType<R>;
if (channelzEnabled) {
// @ts-expect-error typing issues
entityMaps[kind].setElement(id, { ref, getInfo });
entityMap.setElement(id, { ref, getInfo });
}
return ref;
};
Expand Down

0 comments on commit 74ddb3b

Please sign in to comment.