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

Commit 7033f86

Browse files
authored
Improve typing (#7349)
1 parent b2548f0 commit 7033f86

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed

src/@types/global.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ declare global {
163163

164164
interface HTMLAudioElement {
165165
type?: string;
166+
// sinkId & setSinkId are experimental and typescript doesn't know about them
167+
sinkId: string;
168+
setSinkId(outputId: string): void;
169+
}
170+
171+
interface HTMLVideoElement {
172+
type?: string;
173+
// sinkId & setSinkId are experimental and typescript doesn't know about them
174+
sinkId: string;
175+
setSinkId(outputId: string): void;
166176
}
167177

168178
interface HTMLStyleElement {

src/DecryptionFailureTracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ export class DecryptionFailureTracker {
9494
// localStorage.setItem('mx-decryption-failure-event-id-hashes', JSON.stringify(this.trackedEventHashMap));
9595
// }
9696

97-
public eventDecrypted(e: MatrixEvent, err: MatrixError | Error): void {
97+
public eventDecrypted(e: MatrixEvent, err: MatrixError): void {
9898
if (err) {
99-
this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.code));
99+
this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.errcode));
100100
} else {
101101
// Could be an event in the failures, remove it
102102
this.removeDecryptionFailuresForEvent(e);

src/components/structures/MatrixChat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ limitations under the License.
1515
*/
1616

1717
import React, { ComponentType, createRef } from 'react';
18-
import { createClient } from "matrix-js-sdk/src/matrix";
18+
import { createClient } from 'matrix-js-sdk/src/matrix';
19+
import { MatrixError } from 'matrix-js-sdk/src/http-api';
1920
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
2021
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
2122
import { Error as ErrorEvent } from "matrix-analytics-events/types/typescript/Error";
@@ -233,7 +234,7 @@ interface IState {
233234
// When showing Modal dialogs we need to set aria-hidden on the root app element
234235
// and disable it when there are no dialogs
235236
hideToSRUsers: boolean;
236-
syncError?: Error;
237+
syncError?: MatrixError;
237238
resizeNotifier: ResizeNotifier;
238239
serverConfig?: ValidatedServerConfig;
239240
ready: boolean;

src/components/structures/RoomView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { EventType } from 'matrix-js-sdk/src/@types/event';
3333
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
3434
import { CallState, CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
3535
import { throttle } from "lodash";
36+
import { MatrixError } from 'matrix-js-sdk/src/http-api';
3637

3738
import shouldHideEvent from '../../shouldHideEvent';
3839
import { _t } from '../../languageHandler';
@@ -164,7 +165,7 @@ export interface IRoomState {
164165
// error object, as from the matrix client/server API
165166
// If we failed to load information about the room,
166167
// store the error here.
167-
roomLoadError?: Error;
168+
roomLoadError?: MatrixError;
168169
// Have we sent a request to join the room that we're waiting to complete?
169170
joining: boolean;
170171
// this is true if we are fully scrolled-down, and are looking at

src/components/structures/auth/Login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
454454
let errorText: ReactNode = _t("There was a problem communicating with the homeserver, " +
455455
"please try again later.") + (errCode ? " (" + errCode + ")" : "");
456456

457-
if (err.cors === 'rejected') {
457+
if (err["cors"] === 'rejected') { // browser-request specific error field
458458
if (window.location.protocol === 'https:' &&
459459
(this.props.serverConfig.hsUrl.startsWith("http:") ||
460460
!this.props.serverConfig.hsUrl.startsWith("http"))

src/stores/CommunityPrototypeStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
1818
import * as utils from "matrix-js-sdk/src/utils";
1919
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
2020
import { logger } from "matrix-js-sdk/src/logger";
21+
import { Method } from "matrix-js-sdk/src/http-api";
2122

2223
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
2324
import defaultDispatcher from "../dispatcher/dispatcher";
@@ -131,7 +132,7 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
131132
try {
132133
const path = utils.encodeUri("/rooms/$roomId/group_info", { $roomId: room.roomId });
133134
const profile = await this.matrixClient.http.authedRequest(
134-
undefined, "GET", path,
135+
undefined, Method.Get, path,
135136
undefined, undefined,
136137
{ prefix: "/_matrix/client/unstable/im.vector.custom" });
137138
// we use global account data because per-room account data on invites is unreliable

src/stores/RoomViewStore.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
1818

19-
import React from "react";
19+
import React, { ReactNode } from "react";
2020
import { Store } from 'flux/utils';
2121
import { MatrixError } from "matrix-js-sdk/src/http-api";
2222
import { logger } from "matrix-js-sdk/src/logger";
@@ -317,8 +317,8 @@ class RoomViewStore extends Store<ActionPayload> {
317317
}
318318
}
319319

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

324324
if (err.name === "ConnectionError") {

src/utils/ErrorUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function messageForResourceLimitError(
5757
}
5858
}
5959

60-
export function messageForSyncError(err: MatrixError | Error): ReactNode {
60+
export function messageForSyncError(err: MatrixError): ReactNode {
6161
if (err.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
6262
const limitError = messageForResourceLimitError(
6363
err.data.limit_type,

0 commit comments

Comments
 (0)