From c6235c7fd20f0d2ed3ee7ffdcd6aff54a0835487 Mon Sep 17 00:00:00 2001 From: Timo Date: Fri, 21 Jun 2024 11:46:31 +0200 Subject: [PATCH] fix linter with typed binding. --- src/room/useLoadGroupCall.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/room/useLoadGroupCall.ts b/src/room/useLoadGroupCall.ts index 96e38535..6803e3f2 100644 --- a/src/room/useLoadGroupCall.ts +++ b/src/room/useLoadGroupCall.ts @@ -242,17 +242,21 @@ export const useLoadGroupCall = ( ); } if ( - roomSummary?.join_rule === JoinRule.Public || - roomSummary === undefined + roomSummary === undefined || + roomSummary.join_rule === JoinRule.Public ) { room = await client.joinRoom(roomId, { viaServers, }); } else if (roomSummary.join_rule === JoinRule.Knock) { + // bind room summary in this scope so we have it stored in a binding of type `RoomSummary` + // instead of `RoomSummary | undefined`. Because we use it in a promise the linter does not accept + // the type check from the if condition above. + const _roomSummary = roomSummary; let knock: () => void = () => {}; const userPressedAskToJoinPromise: Promise = new Promise( (resolve) => { - if (roomSummary.membership !== KnownMembership.Knock) { + if (_roomSummary.membership !== KnownMembership.Knock) { knock = resolve; } else { // resolve immediately if the user already knocked @@ -260,12 +264,13 @@ export const useLoadGroupCall = ( } }, ); - setState({ kind: "canKnock", roomSummary, knock }); + setState({ kind: "canKnock", roomSummary: _roomSummary, knock }); await userPressedAskToJoinPromise; room = await getRoomByKnocking( roomSummary.room_id, viaServers, - () => setState({ kind: "waitForInvite", roomSummary }), + () => + setState({ kind: "waitForInvite", roomSummary: _roomSummary }), ); } else { throw new Error(