matrix-js-sdk icon indicating copy to clipboard operation
matrix-js-sdk copied to clipboard

Function parameter disrepancies between `CryptoStore` and some subclasses

Open ShadowJonathan opened this issue 4 years ago • 2 comments

export interface ISessionInfo {
    deviceKey?: string;
    sessionId?: string;
    session?: string;
    lastReceivedMessageTs?: number;
}

interface CryptoStore {
    getEndToEndSession(
        deviceKey: string,
        sessionId: string,
        txn: unknown,
        func: (session: ISessionInfo) => void,
    ): void;
}
class Backend implements CryptoStore {
    public getEndToEndSession(
        deviceKey: string,
        sessionId: string,
        txn: IDBTransaction,
        func: (sessions: { [ sessionId: string ]: ISessionInfo }) => void,
    ): void {}
}
class IndexedDBCryptoStore implements CryptoStore {
    public getEndToEndSession(
        deviceKey: string,
        sessionId: string,
        txn: IDBTransaction,
        func: (sessions: { [ sessionId: string ]: ISessionInfo }) => void,
    ): void {}
}

This is allowed, because ISessionInfo (as an interface) only "comments" on the properties of corresponding types, so ISessionInfo, only having optional properties, could apply over any type.

ShadowJonathan avatar Jan 22 '22 23:01 ShadowJonathan

This seems more tractable as a PR than an issue.

turt2live avatar Jan 24 '22 18:01 turt2live

Agreed, I filed this issue as I found it, as it is a subtle bug that not even https://github.com/matrix-org/matrix-js-sdk/issues/2114 would pick up, as ISessionInfo only has optional parameters, which would make ISessionInfo mappable to any type that does not already define one of its properties (f.e. ISessionInfo is mappable to number, string, and null.)

ShadowJonathan avatar Jan 24 '22 22:01 ShadowJonathan