1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-04 05:02:41 +03:00

Fix more typescript --strict violations (#2795)

* Stash tsc fixes

* Iterate

* Iterate

* Iterate

* Fix tests

* Iterate

* Iterate

* Iterate

* Iterate

* Add tests
This commit is contained in:
Michael Telatynski
2022-10-25 18:31:40 +01:00
committed by GitHub
parent 4b3e6939d6
commit 9f2f08dfd3
77 changed files with 829 additions and 733 deletions

View File

@@ -36,7 +36,7 @@ import { IRoomEncryption } from "../RoomList";
*/
export const ENCRYPTION_CLASSES = new Map<string, new (params: IParams) => EncryptionAlgorithm>();
type DecryptionClassParams = Omit<IParams, "deviceId" | "config">;
export type DecryptionClassParams<P extends IParams = IParams> = Omit<P, "deviceId" | "config">;
/**
* map of registered encryption algorithm classes. Map from string to {@link
@@ -52,7 +52,7 @@ export interface IParams {
crypto: Crypto;
olmDevice: OlmDevice;
baseApis: MatrixClient;
roomId: string;
roomId?: string;
config: IRoomEncryption & object;
}
@@ -76,7 +76,7 @@ export abstract class EncryptionAlgorithm {
protected readonly crypto: Crypto;
protected readonly olmDevice: OlmDevice;
protected readonly baseApis: MatrixClient;
protected readonly roomId: string;
protected readonly roomId?: string;
constructor(params: IParams) {
this.userId = params.userId;
@@ -148,7 +148,7 @@ export abstract class DecryptionAlgorithm {
protected readonly crypto: Crypto;
protected readonly olmDevice: OlmDevice;
protected readonly baseApis: MatrixClient;
protected readonly roomId: string;
protected readonly roomId?: string;
constructor(params: DecryptionClassParams) {
this.userId = params.userId;
@@ -296,11 +296,11 @@ export class UnknownDeviceError extends Error {
* module:crypto/algorithms/base.DecryptionAlgorithm|DecryptionAlgorithm}
* implementation
*/
export function registerAlgorithm(
export function registerAlgorithm<P extends IParams = IParams>(
algorithm: string,
encryptor: new (params: IParams) => EncryptionAlgorithm,
decryptor: new (params: DecryptionClassParams) => DecryptionAlgorithm,
encryptor: new (params: P) => EncryptionAlgorithm,
decryptor: new (params: DecryptionClassParams<P>) => DecryptionAlgorithm,
): void {
ENCRYPTION_CLASSES.set(algorithm, encryptor);
DECRYPTION_CLASSES.set(algorithm, decryptor);
ENCRYPTION_CLASSES.set(algorithm, encryptor as new (params: IParams) => EncryptionAlgorithm);
DECRYPTION_CLASSES.set(algorithm, decryptor as new (params: DecryptionClassParams) => DecryptionAlgorithm);
}