Comply with noImplicitAny (#9940)

* Stash noImplicitAny work

* Stash

* Fix imports

* Iterate

* Fix tests

* Delint

* Fix tests
This commit is contained in:
Michael Telatynski
2023-02-13 11:39:16 +00:00
committed by GitHub
parent ac7f69216e
commit 61a63e47f4
359 changed files with 1621 additions and 1353 deletions

View File

@@ -106,5 +106,5 @@ export abstract class AsyncStore<T extends Object> extends EventEmitter {
* Called when the dispatcher broadcasts a dispatch event.
* @param {ActionPayload} payload The event being dispatched.
*/
protected abstract onDispatch(payload: ActionPayload);
protected abstract onDispatch(payload: ActionPayload): void;
}

View File

@@ -126,7 +126,7 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
};
private async updateRooms(): Promise<void> {
let roomIds = SettingsStore.getValue("breadcrumb_rooms");
let roomIds = SettingsStore.getValue<string[]>("breadcrumb_rooms");
if (!roomIds || roomIds.length === 0) roomIds = [];
const rooms = roomIds.map((r) => this.matrixClient.getRoom(r)).filter((r) => !!r);

View File

@@ -22,10 +22,10 @@ import { ActionPayload } from "../dispatcher/payloads";
import { DoAfterSyncPreparedPayload } from "../dispatcher/payloads/DoAfterSyncPreparedPayload";
interface IState {
deferredAction: any;
deferredAction: ActionPayload;
}
const INITIAL_STATE = {
const INITIAL_STATE: IState = {
deferredAction: null,
};

View File

@@ -60,6 +60,7 @@ import {
import { IRoomStateEventsActionPayload } from "../actions/MatrixActionCreators";
import { showCantStartACallDialog } from "../voice-broadcast/utils/showCantStartACallDialog";
import { pauseNonLiveBroadcastFromOtherRoom } from "../voice-broadcast/utils/pauseNonLiveBroadcastFromOtherRoom";
import { ActionPayload } from "../dispatcher/payloads";
const NUM_JOIN_RETRY = 5;
@@ -248,7 +249,7 @@ export class RoomViewStore extends EventEmitter {
}
}
private onDispatch(payload): void {
private onDispatch(payload: ActionPayload): void {
// eslint-disable-line @typescript-eslint/naming-convention
switch (payload.action) {
// view_room:
@@ -258,10 +259,10 @@ export class RoomViewStore extends EventEmitter {
// - event_offset: 100
// - highlighted: true
case Action.ViewRoom:
this.viewRoom(payload);
this.viewRoom(payload as ViewRoomPayload);
break;
case Action.ViewThread:
this.viewThread(payload);
this.viewThread(payload as ThreadPayload);
break;
// for these events blank out the roomId as we are no longer in the RoomView
case "view_welcome_page":
@@ -279,7 +280,7 @@ export class RoomViewStore extends EventEmitter {
this.onRoomStateEvents((payload as IRoomStateEventsActionPayload).event);
break;
case Action.ViewRoomError:
this.viewRoomError(payload);
this.viewRoomError(payload as ViewRoomErrorPayload);
break;
case "will_join":
this.setState({
@@ -294,10 +295,10 @@ export class RoomViewStore extends EventEmitter {
// join_room:
// - opts: options for joinRoom
case Action.JoinRoom:
this.joinRoom(payload);
this.joinRoom(payload as JoinRoomPayload);
break;
case Action.JoinRoomError:
this.joinRoomError(payload);
this.joinRoomError(payload as JoinRoomErrorPayload);
break;
case Action.JoinRoomReady: {
if (this.state.roomId === payload.roomId) {

View File

@@ -30,7 +30,7 @@ export class EchoTransaction extends Whenable<TransactionStatus> {
public readonly startTime = new Date();
public constructor(public readonly auditName, public runFn: RunFn) {
public constructor(public readonly auditName: string, public runFn: RunFn) {
super();
}

View File

@@ -40,7 +40,7 @@ export abstract class GenericEchoChamber<C extends EchoContext, K, V> extends Ev
this.onClientChanged(oldClient, client);
}
protected abstract onClientChanged(oldClient: MatrixClient, newClient: MatrixClient);
protected abstract onClientChanged(oldClient: MatrixClient, newClient: MatrixClient): void;
/**
* Gets a value. If the key is in flight, the cached value will be returned. If

View File

@@ -16,6 +16,7 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
import { GenericEchoChamber, implicitlyReverted, PROPERTY_UPDATED } from "./GenericEchoChamber";
import { getRoomNotifsState, RoomNotifState, setRoomNotifsState } from "../../RoomNotifs";
@@ -33,14 +34,12 @@ export class RoomEchoChamber extends GenericEchoChamber<RoomEchoContext, CachedR
super(context, (k) => this.properties.get(k));
}
protected onClientChanged(oldClient, newClient): void {
protected onClientChanged(oldClient: MatrixClient, newClient: MatrixClient): void {
this.properties.clear();
if (oldClient) {
oldClient.removeListener("accountData", this.onAccountData);
}
oldClient?.removeListener(ClientEvent.AccountData, this.onAccountData);
if (newClient) {
// Register the listeners first
newClient.on("accountData", this.onAccountData);
newClient.on(ClientEvent.AccountData, this.onAccountData);
// Then populate the properties map
this.updateNotificationVolume();

View File

@@ -25,15 +25,13 @@ import { OrderingAlgorithm } from "./OrderingAlgorithm";
import { NotificationColor } from "../../../notifications/NotificationColor";
import { RoomNotificationStateStore } from "../../../notifications/RoomNotificationStateStore";
interface ICategorizedRoomMap {
// @ts-ignore - TS wants this to be a string, but we know better
[category: NotificationColor]: Room[];
}
type CategorizedRoomMap = Partial<{
[category in NotificationColor]: Room[];
}>;
interface ICategoryIndex {
// @ts-ignore - TS wants this to be a string, but we know better
[category: NotificationColor]: number; // integer
}
type CategoryIndex = Partial<{
[category in NotificationColor]: number; // integer
}>;
// Caution: changing this means you'll need to update a bunch of assumptions and
// comments! Check the usage of Category carefully to figure out what needs changing
@@ -69,15 +67,15 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
// tracks when rooms change categories and splices the orderedRooms array as
// needed, preventing many ordering operations.
private indices: ICategoryIndex = {};
private indices: CategoryIndex = {};
public constructor(tagId: TagID, initialSortingAlgorithm: SortAlgorithm) {
super(tagId, initialSortingAlgorithm);
}
// noinspection JSMethodCanBeStatic
private categorizeRooms(rooms: Room[]): ICategorizedRoomMap {
const map: ICategorizedRoomMap = {
private categorizeRooms(rooms: Room[]): CategorizedRoomMap {
const map: CategorizedRoomMap = {
[NotificationColor.Unsent]: [],
[NotificationColor.Red]: [],
[NotificationColor.Grey]: [],
@@ -106,12 +104,18 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
// Every other sorting type affects the categories, not the whole tag.
const categorized = this.categorizeRooms(rooms);
for (const category of Object.keys(categorized)) {
const roomsToOrder = categorized[category];
categorized[category] = sortRoomsWithAlgorithm(roomsToOrder, this.tagId, this.sortingAlgorithm);
if (!isNaN(Number(category))) continue;
const notificationColor = category as unknown as NotificationColor;
const roomsToOrder = categorized[notificationColor];
categorized[notificationColor] = sortRoomsWithAlgorithm(
roomsToOrder,
this.tagId,
this.sortingAlgorithm,
);
}
const newlyOrganized: Room[] = [];
const newIndices: ICategoryIndex = {};
const newIndices: CategoryIndex = {};
for (const category of CATEGORY_ORDER) {
newIndices[category] = newlyOrganized.length;
@@ -206,7 +210,7 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
}
// noinspection JSMethodCanBeStatic
private getCategoryFromIndices(index: number, indices: ICategoryIndex): NotificationColor {
private getCategoryFromIndices(index: number, indices: CategoryIndex): NotificationColor {
for (let i = 0; i < CATEGORY_ORDER.length; i++) {
const category = CATEGORY_ORDER[i];
const isLast = i === CATEGORY_ORDER.length - 1;
@@ -226,7 +230,7 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
nRooms: number,
fromCategory: NotificationColor,
toCategory: NotificationColor,
indices: ICategoryIndex,
indices: CategoryIndex,
): void {
// We have to update the index of the category *after* the from/toCategory variables
// in order to update the indices correctly. Because the room is moving from/to those
@@ -238,7 +242,7 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
this.alterCategoryPositionBy(toCategory, +nRooms, indices);
}
private alterCategoryPositionBy(category: NotificationColor, n: number, indices: ICategoryIndex): void {
private alterCategoryPositionBy(category: NotificationColor, n: number, indices: CategoryIndex): void {
// Note: when we alter a category's index, we actually have to modify the ones following
// the target and not the target itself.

View File

@@ -35,7 +35,7 @@ export class NaturalAlgorithm extends OrderingAlgorithm {
this.cachedOrderedRooms = sortRoomsWithAlgorithm(rooms, this.tagId, this.sortingAlgorithm);
}
public handleRoomUpdate(room, cause): boolean {
public handleRoomUpdate(room: Room, cause: RoomUpdateCause): boolean {
const isSplice = cause === RoomUpdateCause.NewRoom || cause === RoomUpdateCause.RoomRemoved;
const isInPlace = cause === RoomUpdateCause.Timeline || cause === RoomUpdateCause.ReadReceipt;
if (!isSplice && !isInPlace) {

View File

@@ -185,7 +185,14 @@ export class StopGapWidgetDriver extends WidgetDriver {
let rememberApproved = false;
if (missing.size > 0) {
try {
const [result] = await Modal.createDialog(WidgetCapabilitiesPromptDialog, {
const [result] = await Modal.createDialog<
[
{
approved: Capability[];
remember: boolean;
},
]
>(WidgetCapabilitiesPromptDialog, {
requestedCapabilities: missing,
widget: this.forWidget,
widgetKind: this.forWidgetKind,

View File

@@ -96,14 +96,13 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
private static internalInstance: WidgetLayoutStore;
private byRoom: {
[roomId: string]: {
// @ts-ignore - TS wants a string key, but we know better
[container: Container]: {
[roomId: string]: Partial<{
[container in Container]: {
ordered: IApp[];
height?: number;
distributions?: number[];
};
};
}>;
} = {};
private pinnedRef: string;
@@ -391,7 +390,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
if (numbers.length === 2) numbers.splice(1, 0, remaining);
if (numbers.length === 1) numbers.push(remaining);
const localLayout = {};
const localLayout: Record<string, IStoredLayout> = {};
widgets.forEach((w, i) => {
localLayout[w.id] = {
container: container,
@@ -410,7 +409,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
public setContainerHeight(room: Room, container: Container, height: number): void {
const widgets = this.getContainerWidgets(room, container);
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
const localLayout = {};
const localLayout: Record<string, IStoredLayout> = {};
widgets.forEach((w, i) => {
localLayout[w.id] = {
container: container,
@@ -433,7 +432,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
const height = this.byRoom[room.roomId]?.[container]?.height;
const localLayout = {};
const localLayout: Record<string, IStoredLayout> = {};
widgets.forEach((w, i) => {
localLayout[w.id] = {
container: container,
@@ -449,7 +448,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
const allWidgets = this.getAllWidgets(room);
if (!allWidgets.some(([w]) => w.id === widget.id)) return; // invalid
// Prepare other containers (potentially move widgets to obey the following rules)
const newLayout = {};
const newLayout: Record<string, IStoredLayout> = {};
switch (toContainer) {
case Container.Right:
// new "right" widget
@@ -516,11 +515,11 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
const containers = this.byRoom[room.roomId];
if (!containers) return [];
const ret = [];
const ret: [IApp, Container][] = [];
for (const container of Object.keys(containers)) {
const widgets = containers[container].ordered;
const widgets = containers[container as Container].ordered;
for (const widget of widgets) {
ret.push([widget, container]);
ret.push([widget, container as Container]);
}
}
return ret;

View File

@@ -61,7 +61,10 @@ export class WidgetPermissionStore {
public setOIDCState(widget: Widget, kind: WidgetKind, roomId: string, newState: OIDCState): void {
const settingsKey = this.packSettingKey(widget, kind, roomId);
let currentValues = SettingsStore.getValue("widgetOpenIDPermissions");
let currentValues = SettingsStore.getValue<{
allow?: string[];
deny?: string[];
}>("widgetOpenIDPermissions");
if (!currentValues) {
currentValues = {};
}