Conform more code to strictNullChecks (#10383

* Update matrix-widget-api

* Conform more code to `strictNullChecks`

* Iterate
This commit is contained in:
Michael Telatynski 2023-03-16 10:35:17 +00:00 committed by GitHub
parent aae9dfbb7d
commit 9c816bb720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 112 additions and 93 deletions

View file

@ -192,7 +192,7 @@ export class RoomPermalinkCreator {
isHostInRegex(domain, this.allowedHostsRegexps)
);
});
const maxEntry = allowedEntries.reduce(
const maxEntry = allowedEntries.reduce<[string | null, number]>(
(max, entry) => {
return entry[1] > max[1] ? entry : max;
},
@ -329,7 +329,7 @@ export function tryTransformEntityToPermalink(entity: string): string | null {
if (permalinkParts.roomIdOrAlias) {
const eventIdPart = permalinkParts.eventId ? `/${permalinkParts.eventId}` : "";
let pl = matrixtoBaseUrl + `/#/${permalinkParts.roomIdOrAlias}${eventIdPart}`;
if (permalinkParts.viaServers.length > 0) {
if (permalinkParts.viaServers?.length) {
pl += new MatrixToPermalinkConstructor().encodeServerCandidates(permalinkParts.viaServers);
}
return pl;
@ -376,7 +376,7 @@ export function tryTransformPermalinkToLocalHref(permalink: string): string {
if (permalinkParts.roomIdOrAlias) {
const eventIdPart = permalinkParts.eventId ? `/${permalinkParts.eventId}` : "";
permalink = `#/room/${permalinkParts.roomIdOrAlias}${eventIdPart}`;
if (permalinkParts.viaServers.length > 0) {
if (permalinkParts.viaServers?.length) {
permalink += new MatrixToPermalinkConstructor().encodeServerCandidates(permalinkParts.viaServers);
}
} else if (permalinkParts.userId) {
@ -475,7 +475,7 @@ function isHostnameIpAddress(hostname: string): boolean {
return isIp(hostname);
}
export const calculateRoomVia = (room: Room): string[] => {
export const calculateRoomVia = (room: Room): string[] | undefined => {
const permalinkCreator = new RoomPermalinkCreator(room);
permalinkCreator.load();
return permalinkCreator.serverCandidates;