Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Improve typing (#7349)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Dec 14, 2021
1 parent b2548f0 commit 7033f86
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ declare global {

interface HTMLAudioElement {
type?: string;
// sinkId & setSinkId are experimental and typescript doesn't know about them
sinkId: string;
setSinkId(outputId: string): void;
}

interface HTMLVideoElement {
type?: string;
// sinkId & setSinkId are experimental and typescript doesn't know about them
sinkId: string;
setSinkId(outputId: string): void;
}

interface HTMLStyleElement {
Expand Down
4 changes: 2 additions & 2 deletions src/DecryptionFailureTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export class DecryptionFailureTracker {
// localStorage.setItem('mx-decryption-failure-event-id-hashes', JSON.stringify(this.trackedEventHashMap));
// }

public eventDecrypted(e: MatrixEvent, err: MatrixError | Error): void {
public eventDecrypted(e: MatrixEvent, err: MatrixError): void {
if (err) {
this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.code));
this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.errcode));
} else {
// Could be an event in the failures, remove it
this.removeDecryptionFailuresForEvent(e);
Expand Down
5 changes: 3 additions & 2 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ limitations under the License.
*/

import React, { ComponentType, createRef } from 'react';
import { createClient } from "matrix-js-sdk/src/matrix";
import { createClient } from 'matrix-js-sdk/src/matrix';
import { MatrixError } from 'matrix-js-sdk/src/http-api';
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Error as ErrorEvent } from "matrix-analytics-events/types/typescript/Error";
Expand Down Expand Up @@ -233,7 +234,7 @@ interface IState {
// When showing Modal dialogs we need to set aria-hidden on the root app element
// and disable it when there are no dialogs
hideToSRUsers: boolean;
syncError?: Error;
syncError?: MatrixError;
resizeNotifier: ResizeNotifier;
serverConfig?: ValidatedServerConfig;
ready: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { EventType } from 'matrix-js-sdk/src/@types/event';
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
import { CallState, CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
import { throttle } from "lodash";
import { MatrixError } from 'matrix-js-sdk/src/http-api';

import shouldHideEvent from '../../shouldHideEvent';
import { _t } from '../../languageHandler';
Expand Down Expand Up @@ -164,7 +165,7 @@ export interface IRoomState {
// error object, as from the matrix client/server API
// If we failed to load information about the room,
// store the error here.
roomLoadError?: Error;
roomLoadError?: MatrixError;
// Have we sent a request to join the room that we're waiting to complete?
joining: boolean;
// this is true if we are fully scrolled-down, and are looking at
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
let errorText: ReactNode = _t("There was a problem communicating with the homeserver, " +
"please try again later.") + (errCode ? " (" + errCode + ")" : "");

if (err.cors === 'rejected') {
if (err["cors"] === 'rejected') { // browser-request specific error field
if (window.location.protocol === 'https:' &&
(this.props.serverConfig.hsUrl.startsWith("http:") ||
!this.props.serverConfig.hsUrl.startsWith("http"))
Expand Down
3 changes: 2 additions & 1 deletion src/stores/CommunityPrototypeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import * as utils from "matrix-js-sdk/src/utils";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
import { logger } from "matrix-js-sdk/src/logger";
import { Method } from "matrix-js-sdk/src/http-api";

import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
import defaultDispatcher from "../dispatcher/dispatcher";
Expand Down Expand Up @@ -131,7 +132,7 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
try {
const path = utils.encodeUri("/rooms/$roomId/group_info", { $roomId: room.roomId });
const profile = await this.matrixClient.http.authedRequest(
undefined, "GET", path,
undefined, Method.Get, path,
undefined, undefined,
{ prefix: "/_matrix/client/unstable/im.vector.custom" });
// we use global account data because per-room account data on invites is unreliable
Expand Down
6 changes: 3 additions & 3 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import React, { ReactNode } from "react";
import { Store } from 'flux/utils';
import { MatrixError } from "matrix-js-sdk/src/http-api";
import { logger } from "matrix-js-sdk/src/logger";
Expand Down Expand Up @@ -317,8 +317,8 @@ class RoomViewStore extends Store<ActionPayload> {
}
}

public showJoinRoomError(err: Error | MatrixError, roomId: string) {
let msg = err.message ? err.message : JSON.stringify(err);
public showJoinRoomError(err: MatrixError, roomId: string) {
let msg: ReactNode = err.message ? err.message : JSON.stringify(err);
logger.log("Failed to join room:", msg);

if (err.name === "ConnectionError") {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ErrorUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function messageForResourceLimitError(
}
}

export function messageForSyncError(err: MatrixError | Error): ReactNode {
export function messageForSyncError(err: MatrixError): ReactNode {
if (err.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
const limitError = messageForResourceLimitError(
err.data.limit_type,
Expand Down

0 comments on commit 7033f86

Please sign in to comment.