diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index c7e65ff77..679a6afba 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -23,6 +23,7 @@ declare global { // use `number` as the return type in all cases for global.set{Interval,Timeout}, // so we don't accidentally use the methods on NodeJS.Timeout - they only exist in a subset of environments. // The overload for clear{Interval,Timeout} is resolved as expected. + // We use `ReturnType` in the code to be agnostic of if this definition gets loaded. function setInterval(handler: TimerHandler, timeout: number, ...arguments: any[]): number; function setTimeout(handler: TimerHandler, timeout: number, ...arguments: any[]): number; diff --git a/src/client.ts b/src/client.ts index 78249b121..a705f5df5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -913,7 +913,7 @@ export class MatrixClient extends TypedEventEmitter; protected syncedLeftRooms = false; protected clientOpts: IStoredClientOpts; - protected clientWellKnownIntervalID: number; + protected clientWellKnownIntervalID: ReturnType; protected canResetTimelineCallback: ResetTimelineCallback; // The pushprocessor caches useful things, so keep one and re-use it @@ -931,7 +931,7 @@ export class MatrixClient extends TypedEventEmitter; protected turnServers: ITurnServer[] = []; protected turnServersExpiry = 0; - protected checkTurnServersIntervalID: number; + protected checkTurnServersIntervalID: ReturnType; protected exportedOlmDeviceToImport: IOlmDevice; protected txnCtr = 0; protected mediaHandler = new MediaHandler(this); diff --git a/src/crypto/DeviceList.ts b/src/crypto/DeviceList.ts index 40c055c7b..000e79f93 100644 --- a/src/crypto/DeviceList.ts +++ b/src/crypto/DeviceList.ts @@ -95,7 +95,7 @@ export class DeviceList extends TypedEventEmitter = null; // True if we have fetched data from the server or loaded a non-empty // set of device data from the store private hasFetched: boolean = null; diff --git a/src/crypto/OutgoingRoomKeyRequestManager.ts b/src/crypto/OutgoingRoomKeyRequestManager.ts index 832294110..013a6d08e 100644 --- a/src/crypto/OutgoingRoomKeyRequestManager.ts +++ b/src/crypto/OutgoingRoomKeyRequestManager.ts @@ -78,7 +78,7 @@ export enum RoomKeyRequestState { export class OutgoingRoomKeyRequestManager { // handle for the delayed call to sendOutgoingRoomKeyRequests. Non-null // if the callback has been set, or if it is still running. - private sendOutgoingRoomKeyRequestsTimer: number = null; + private sendOutgoingRoomKeyRequestsTimer: ReturnType = null; // sanity check to ensure that we don't end up with two concurrent runs // of sendOutgoingRoomKeyRequests diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 0842dda53..df18d83a0 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -309,7 +309,7 @@ export class Crypto extends TypedEventEmitter; /** * Cryptography bits diff --git a/src/crypto/recoverykey.ts b/src/crypto/recoverykey.ts index 5c54e6085..124f6c77b 100644 --- a/src/crypto/recoverykey.ts +++ b/src/crypto/recoverykey.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import bs58 from 'bs58'; +import * as bs58 from 'bs58'; // picked arbitrarily but to try & avoid clashing with any bitcoin ones // (which are also base58 encoded, but bitcoin's involve a lot more hashing) diff --git a/src/crypto/store/indexeddb-crypto-store-backend.ts b/src/crypto/store/indexeddb-crypto-store-backend.ts index 8e311a1a2..6666fcf01 100644 --- a/src/crypto/store/indexeddb-crypto-store-backend.ts +++ b/src/crypto/store/indexeddb-crypto-store-backend.ts @@ -873,7 +873,7 @@ export class Backend implements CryptoStore { public doTxn( mode: Mode, - stores: Iterable, + stores: string | string[], func: (txn: IDBTransaction) => T, log: PrefixedLogger = logger, ): Promise { diff --git a/src/crypto/verification/Base.ts b/src/crypto/verification/Base.ts index 68e9c96fc..351004990 100644 --- a/src/crypto/verification/Base.ts +++ b/src/crypto/verification/Base.ts @@ -55,7 +55,7 @@ export class VerificationBase< private cancelled = false; private _done = false; private promise: Promise = null; - private transactionTimeoutTimer: number = null; + private transactionTimeoutTimer: ReturnType = null; protected expectedEvent: string; private resolve: () => void; private reject: (e: Error | MatrixEvent) => void; diff --git a/src/crypto/verification/request/VerificationRequest.ts b/src/crypto/verification/request/VerificationRequest.ts index 8af56f354..e8eb5b8d3 100644 --- a/src/crypto/verification/request/VerificationRequest.ts +++ b/src/crypto/verification/request/VerificationRequest.ts @@ -95,7 +95,7 @@ export class VerificationRequest< private eventsByUs = new Map(); private eventsByThem = new Map(); private _observeOnly = false; - private timeoutTimer: number = null; + private timeoutTimer: ReturnType = null; private _accepting = false; private _declining = false; private verifierHasFinished = false; diff --git a/src/index.ts b/src/index.ts index faab0fed0..c651438fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import request from "request"; +import * as request from "request"; import * as matrixcs from "./matrix"; import * as utils from "./utils"; diff --git a/src/models/beacon.ts b/src/models/beacon.ts index caea77327..a4f769458 100644 --- a/src/models/beacon.ts +++ b/src/models/beacon.ts @@ -54,7 +54,7 @@ export class Beacon extends TypedEventEmitter; private _latestLocationState: BeaconLocationState | undefined; constructor( diff --git a/src/store/index.ts b/src/store/index.ts index c47bd20ad..f71f7c093 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -37,6 +37,10 @@ export interface ISavedSync { export interface IStore { readonly accountData: Record; // type : content + // XXX: The indexeddb store exposes a non-standard emitter for the "degraded" event + // for when it falls back to being a memory store due to errors. + on?: (event: string, handler: (...args: any[]) => void) => void; + /** @return {Promise} whether or not the database was newly created in this session. */ isNewlyCreated(): Promise; @@ -105,7 +109,7 @@ export interface IStore { /** * No-op. * @param {Room} room - * @param {integer} limit + * @param {number} limit * @return {Array} */ scrollback(room: Room, limit: number): MatrixEvent[]; diff --git a/src/sync.ts b/src/sync.ts index 0791920a9..d3aec0d5c 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -152,7 +152,7 @@ export class SyncApi { private syncStateData: ISyncStateData = null; // additional data (eg. error object for failed sync) private catchingUp = false; private running = false; - private keepAliveTimer: number = null; + private keepAliveTimer: ReturnType = null; private connectionReturnedDefer: IDeferred = null; private notifEvents: MatrixEvent[] = []; // accumulator of sync events in the current sync response private failedSyncCount = 0; // Number of consecutive failed /sync requests @@ -1390,7 +1390,7 @@ export class SyncApi { * Starts polling the connectivity check endpoint * @param {number} delay How long to delay until the first poll. * defaults to a short, randomised interval (to prevent - * tightlooping if /versions succeeds but /sync etc. fail). + * tight-looping if /versions succeeds but /sync etc. fail). * @return {promise} which resolves once the connection returns */ private startKeepAlives(delay?: number): Promise { diff --git a/src/utils.ts b/src/utils.ts index 777531286..4885fb948 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -23,7 +23,7 @@ limitations under the License. import unhomoglyph from "unhomoglyph"; import promiseRetry from "p-retry"; -import type NodeCrypto from "crypto"; +import type * as NodeCrypto from "crypto"; import { MatrixEvent } from "."; import { M_TIMESTAMP } from "./@types/location"; diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index dcc1016a6..d6a574713 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -298,7 +298,7 @@ export class MatrixCall extends TypedEventEmitter; // The logic of when & if a call is on hold is nontrivial and explained in is*OnHold // This flag represents whether we want the other party to be on hold @@ -322,7 +322,7 @@ export class MatrixCall extends TypedEventEmitter; private callLength = 0; constructor(opts: CallOpts) { @@ -708,9 +708,9 @@ export class MatrixCall extends TypedEventEmitter { stats.push(item[1]); - } + }); return stats; } diff --git a/src/webrtc/callFeed.ts b/src/webrtc/callFeed.ts index 8f61afaa5..fbe308e53 100644 --- a/src/webrtc/callFeed.ts +++ b/src/webrtc/callFeed.ts @@ -69,7 +69,7 @@ export class CallFeed extends TypedEventEmitter private frequencyBinCount: Float32Array; private speakingThreshold = SPEAKING_THRESHOLD; private speaking = false; - private volumeLooperTimeout: number; + private volumeLooperTimeout: ReturnType; constructor(opts: ICallFeedOpts) { super();