Make more of the codebase conform to strict types (#10857)

This commit is contained in:
Michael Telatynski 2023-05-16 14:25:43 +01:00 committed by GitHub
parent 7f017a84c2
commit 6a3f59cc76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 127 additions and 121 deletions

View file

@ -16,6 +16,7 @@ limitations under the License.
import { SERVICE_TYPES } from "matrix-js-sdk/src/service-types";
import { logger } from "matrix-js-sdk/src/logger";
import { HTTPError } from "matrix-js-sdk/src/http-api";
import SdkConfig from "../SdkConfig";
import { MatrixClientPeg } from "../MatrixClientPeg";
@ -39,7 +40,7 @@ export async function doesIdentityServerHaveTerms(fullUrl: string): Promise<bool
terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl);
} catch (e) {
logger.error(e);
if (e.cors === "rejected" || e.httpStatus === 404) {
if (e.cors === "rejected" || (e instanceof HTTPError && e.httpStatus === 404)) {
terms = null;
} else {
throw e;

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { IDeferred, defer } from "matrix-js-sdk/src/utils";
/**
A countdown timer, exposing a promise api.
A timer starts in a non-started state,
@ -28,9 +30,7 @@ a new one through `clone()` or `cloneIfRun()`.
export default class Timer {
private timerHandle?: number;
private startTs?: number;
private promise: Promise<void>;
private resolve: () => void;
private reject: (err: Error) => void;
private deferred!: IDeferred<void>;
public constructor(private timeout: number) {
this.setNotStarted();
@ -39,10 +39,8 @@ export default class Timer {
private setNotStarted(): void {
this.timerHandle = undefined;
this.startTs = undefined;
this.promise = new Promise<void>((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
}).finally(() => {
this.deferred = defer();
this.deferred.promise = this.deferred.promise.finally(() => {
this.timerHandle = undefined;
});
}
@ -51,7 +49,7 @@ export default class Timer {
const now = Date.now();
const elapsed = now - this.startTs!;
if (elapsed >= this.timeout) {
this.resolve();
this.deferred.resolve();
this.setNotStarted();
} else {
const delta = this.timeout - elapsed;
@ -108,7 +106,7 @@ export default class Timer {
public abort(): Timer {
if (this.isRunning()) {
clearTimeout(this.timerHandle);
this.reject(new Error("Timer was aborted."));
this.deferred.reject(new Error("Timer was aborted."));
this.setNotStarted();
}
return this;
@ -120,7 +118,7 @@ export default class Timer {
*@return {Promise}
*/
public finished(): Promise<void> {
return this.promise;
return this.deferred.promise;
}
public isRunning(): boolean {

View file

@ -65,7 +65,7 @@ export const useOwnLiveBeacons = (liveBeaconIds: BeaconIdentifier[]): LiveBeacon
// select the beacon with latest expiry to display expiry time
const beacon = liveBeaconIds
.map((beaconId) => OwnBeaconStore.instance.getBeaconById(beaconId))
.map((beaconId) => OwnBeaconStore.instance.getBeaconById(beaconId)!)
.sort(sortBeaconsByLatestExpiry)
.shift();