1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

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

@ -42,7 +42,7 @@ describe("formatSeconds", () => {
});
describe("formatRelativeTime", () => {
let dateSpy;
let dateSpy: jest.SpyInstance<number, []>;
beforeAll(() => {
dateSpy = jest
.spyOn(global.Date, "now")

View File

@ -18,6 +18,8 @@ import { TextEncoder } from "util";
import nodeCrypto from "crypto";
import { Crypto } from "@peculiar/webcrypto";
import type * as MegolmExportEncryptionExport from "../../src/utils/MegolmExportEncryption";
const webCrypto = new Crypto();
function getRandomValues<T extends ArrayBufferView>(buf: T): T {
@ -70,7 +72,7 @@ function stringToArray(s: string): ArrayBufferLike {
}
describe("MegolmExportEncryption", function () {
let MegolmExportEncryption;
let MegolmExportEncryption: typeof MegolmExportEncryptionExport;
beforeEach(() => {
window.crypto = {
@ -131,7 +133,7 @@ cissyYBxjsfsAn
// TODO find a subtlecrypto shim which doesn't break this test
it.skip("should decrypt a range of inputs", function () {
function next(i) {
function next(i: number): unknown {
if (i >= TEST_VECTORS.length) {
return;
}

View File

@ -29,7 +29,7 @@ const MXID1 = "@user1:server";
const MXID2 = "@user2:server";
const MXID3 = "@user3:server";
const MXID_PROFILE_STATES = {
const MXID_PROFILE_STATES: Record<string, Promise<any>> = {
[MXID1]: Promise.resolve({}),
[MXID2]: Promise.reject({ errcode: "M_FORBIDDEN" }),
[MXID3]: Promise.reject({ errcode: "M_NOT_FOUND" }),

View File

@ -22,14 +22,14 @@ import DMRoomMap from "../../src/utils/DMRoomMap";
function mkClient(selfTrust = false) {
return {
getUserId: () => "@self:localhost",
checkUserTrust: (userId) => ({
checkUserTrust: (userId: string) => ({
isCrossSigningVerified: () => userId[1] == "T",
wasCrossSigningVerified: () => userId[1] == "T" || userId[1] == "W",
}),
checkDeviceTrust: (userId, deviceId) => ({
checkDeviceTrust: (userId: string, deviceId: string) => ({
isVerified: () => (userId === "@self:localhost" ? selfTrust : userId[2] == "T"),
}),
getStoredDevicesForUser: (userId) => ["DEVICE"],
getStoredDevicesForUser: (userId: string) => ["DEVICE"],
} as unknown as MatrixClient;
}
@ -61,7 +61,7 @@ describe("mkClient self-test", function () {
describe("shieldStatusForMembership self-trust behaviour", function () {
beforeAll(() => {
const mockInstance = {
getUserIdForRoomId: (roomId) => (roomId === "DM" ? "@any:h" : null),
getUserIdForRoomId: (roomId: string) => (roomId === "DM" ? "@any:h" : null),
} as unknown as DMRoomMap;
jest.spyOn(DMRoomMap, "shared").mockReturnValue(mockInstance);
});
@ -164,7 +164,7 @@ describe("shieldStatusForMembership self-trust behaviour", function () {
describe("shieldStatusForMembership other-trust behaviour", function () {
beforeAll(() => {
const mockInstance = {
getUserIdForRoomId: (roomId) => (roomId === "DM" ? "@any:h" : null),
getUserIdForRoomId: (roomId: string) => (roomId === "DM" ? "@any:h" : null),
} as unknown as DMRoomMap;
jest.spyOn(DMRoomMap, "shared").mockReturnValue(mockInstance);
});

View File

@ -15,8 +15,10 @@ limitations under the License.
*/
import { logger } from "matrix-js-sdk/src/logger";
import { Mocked } from "jest-mock";
import {
GenericPosition,
GeolocationError,
getGeoUri,
mapGeolocationError,
@ -27,7 +29,7 @@ import { getCurrentPosition } from "../../../src/utils/beacon/geolocation";
import { makeGeolocationPosition, mockGeolocation, getMockGeolocationPositionError } from "../../test-utils";
describe("geolocation utilities", () => {
let geolocation;
let geolocation: Mocked<Geolocation>;
const defaultPosition = makeGeolocationPosition({});
// 14.03.2022 16:15
@ -45,7 +47,7 @@ describe("geolocation utilities", () => {
describe("getGeoUri", () => {
it("Renders a URI with only lat and lon", () => {
const pos = {
const pos: GenericPosition = {
latitude: 43.2,
longitude: 12.4,
altitude: undefined,
@ -57,7 +59,7 @@ describe("geolocation utilities", () => {
});
it("Nulls in location are not shown in URI", () => {
const pos = {
const pos: GenericPosition = {
latitude: 43.2,
longitude: 12.4,
altitude: null,
@ -69,7 +71,7 @@ describe("geolocation utilities", () => {
});
it("Renders a URI with 3 coords", () => {
const pos = {
const pos: GenericPosition = {
latitude: 43.2,
longitude: 12.4,
altitude: 332.54,
@ -80,7 +82,7 @@ describe("geolocation utilities", () => {
});
it("Renders a URI with accuracy", () => {
const pos = {
const pos: GenericPosition = {
latitude: 43.2,
longitude: 12.4,
altitude: undefined,
@ -193,9 +195,10 @@ describe("geolocation utilities", () => {
it("maps geolocation position error and calls error handler", () => {
// suppress expected errors from test log
jest.spyOn(logger, "error").mockImplementation(() => {});
geolocation.watchPosition.mockImplementation((_callback, error) =>
error(getMockGeolocationPositionError(1, "message")),
);
geolocation.watchPosition.mockImplementation((_callback, error) => {
error(getMockGeolocationPositionError(1, "message"));
return -1;
});
const positionHandler = jest.fn();
const errorHandler = jest.fn();
watchPosition(positionHandler, errorHandler);

View File

@ -291,7 +291,7 @@ describe("export", function () {
it("tests the file extension splitter", function () {
const exporter = new PlainTextExporter(mockRoom, ExportType.Beginning, mockExportOptions, null);
const fileNameWithExtensions = {
const fileNameWithExtensions: Record<string, [string, string]> = {
"": ["", ""],
"name": ["name", ""],
"name.txt": ["name", ".txt"],

View File

@ -67,7 +67,7 @@ describe("local-room", () => {
});
describe("for a local room", () => {
let prom;
let prom: Promise<unknown>;
beforeEach(() => {
jest.spyOn(defaultDispatcher, "dispatch");

View File

@ -41,8 +41,8 @@ describe("isSelfLocation", () => {
[M_TEXT.name]: "",
[M_TIMESTAMP.name]: 0,
// Note: no m.asset!
};
expect(isSelfLocation(content as ILocationContent)).toBe(true);
} as unknown as ILocationContent;
expect(isSelfLocation(content)).toBe(true);
});
it("Returns true for a missing m.asset type", () => {
@ -56,8 +56,8 @@ describe("isSelfLocation", () => {
[M_ASSET.name]: {
// Note: no type!
},
};
expect(isSelfLocation(content as ILocationContent)).toBe(true);
} as unknown as ILocationContent;
expect(isSelfLocation(content)).toBe(true);
});
it("Returns false for an unknown asset type", () => {

View File

@ -15,6 +15,7 @@ limitations under the License.
*/
import { EventEmitter } from "events";
import { MatrixClient, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { waitForMember } from "../../src/utils/membership";
@ -22,14 +23,14 @@ import { waitForMember } from "../../src/utils/membership";
const timeout = 30;
describe("waitForMember", () => {
let client;
let client: EventEmitter;
beforeEach(() => {
client = new EventEmitter();
});
it("resolves with false if the timeout is reached", (done) => {
waitForMember(client, "", "", { timeout: 0 }).then((r) => {
waitForMember(<MatrixClient>client, "", "", { timeout: 0 }).then((r) => {
expect(r).toBe(false);
done();
});
@ -38,7 +39,7 @@ describe("waitForMember", () => {
it("resolves with false if the timeout is reached, even if other RoomState.newMember events fire", (done) => {
const roomId = "!roomId:domain";
const userId = "@clientId:domain";
waitForMember(client, roomId, userId, { timeout }).then((r) => {
waitForMember(<MatrixClient>client, roomId, userId, { timeout }).then((r) => {
expect(r).toBe(false);
done();
});
@ -48,9 +49,9 @@ describe("waitForMember", () => {
it("resolves with true if RoomState.newMember fires", (done) => {
const roomId = "!roomId:domain";
const userId = "@clientId:domain";
waitForMember(client, roomId, userId, { timeout }).then((r) => {
waitForMember(<MatrixClient>client, roomId, userId, { timeout }).then((r) => {
expect(r).toBe(true);
expect(client.listeners("RoomState.newMember").length).toBe(0);
expect((<MatrixClient>client).listeners(RoomStateEvent.NewMember).length).toBe(0);
done();
});
client.emit("RoomState.newMember", undefined, undefined, { roomId, userId });

View File

@ -15,7 +15,7 @@ limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { mocked } from "jest-mock";
import { Mocked, mocked } from "jest-mock";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
@ -36,9 +36,9 @@ import { MatrixClientPeg } from "../../src/MatrixClientPeg";
jest.mock("../../src/settings/SettingsStore");
describe("notifications", () => {
let accountDataStore = {};
let mockClient;
let accountDataEventKey;
let accountDataStore: Record<string, MatrixEvent> = {};
let mockClient: Mocked<MatrixClient>;
let accountDataEventKey: string;
beforeEach(() => {
jest.clearAllMocks();

View File

@ -43,7 +43,7 @@ describe("Permalinks", function () {
serverACLContent?: { deny?: string[]; allow?: string[] },
): Room {
members.forEach((m) => (m.membership = "join"));
const powerLevelsUsers = members.reduce((pl, member) => {
const powerLevelsUsers = members.reduce<Record<string, number>>((pl, member) => {
if (Number.isFinite(member.powerLevel)) {
pl[member.userId] = member.powerLevel;
}