Cherry-pick typing fix from #2061
Cherry-pick typing fix from #2061

Co-authored-by: Tommie Gannert <14b9b34aa8252e69dc98c6bb9bba67a2603813d2@gannert.se>

matrix-org/dendrite,matrix-org/dendrite,matrix-org/dendrite,matrix-org/dendrite