Compile error in realtime hooks in typescript runtime server

Whenever adding a realtime hooks it is showing error same types of error. When adding MatchmakerAdd hook, it is showing as :

Argument of type 'RtBeforeHookFunction<EnvelopeMatchmakerAdd>' is not assignable to parameter of type 'RtBeforeHookFunction<Envelope>

Whenver adding ChannelJoin hook, it is showing as :

Argument of type 'RtBeforeHookFunction<EnvelopeChannelJoin>' is not assignable to parameter of type 'RtBeforeHookFunction<Envelope>'.
  Types of parameters 'envelope' and 'envelope' are incompatible.
    Type 'Envelope' is not assignable to type 'EnvelopeChannelJoin'.
      Type 'EnvelopeChannel' is not assignable to type 'EnvelopeChannelJoin'.

main.ts

let InitModule: nkruntime.InitModule = function (
  ctx: nkruntime.Context,
  logger: nkruntime.Logger,
  nk: nkruntime.Nakama,
  initializer: nkruntime.Initializer
) {
  initializer.registerRtBefore("ChannelJoin", beforeChannelJoin);
};
let beforeChannelJoin: nkruntime.RtBeforeHookFunction<nkruntime.EnvelopeChannelJoin> = function (
  ctx: nkruntime.Context,
  logger: nkruntime.Logger,
  nk: nkruntime.Nakama,
  envelope: nkruntime.EnvelopeChannelJoin
): nkruntime.EnvelopeChannelJoin | void {
  // If the channel join is a DirectMessage type, check to see if the user is friends with the recipient first
  if (envelope.channelJoin.type == nkruntime.ChanType.DirectMessage) {
    const result = nk.friendsList(ctx.userId, null, 0, null);
    const filtered = result.friends.filter(function (friend) {
      return friend.user.userId == envelope.channelJoin.target;
    });

    if (filtered.length == 0) {
      throw new Error(
        "You cannot direct message someone you are not friends with."
      );
    }
  }

  return envelope;
};