Improve typing (#9474)
This commit is contained in:
parent
5f59ce182e
commit
fde9a527a7
4 changed files with 10 additions and 10 deletions
|
@ -1 +1 @@
|
||||||
14
|
16
|
||||||
|
|
|
@ -22,6 +22,7 @@ import classNames from 'classnames';
|
||||||
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
|
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
|
||||||
import { IUsageLimit } from 'matrix-js-sdk/src/@types/partials';
|
import { IUsageLimit } from 'matrix-js-sdk/src/@types/partials';
|
||||||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||||
|
import { MatrixError } from 'matrix-js-sdk/src/matrix';
|
||||||
|
|
||||||
import { isOnlyCtrlOrCmdKeyEvent, Key } from '../../Keyboard';
|
import { isOnlyCtrlOrCmdKeyEvent, Key } from '../../Keyboard';
|
||||||
import PageTypes from '../../PageTypes';
|
import PageTypes from '../../PageTypes';
|
||||||
|
@ -288,8 +289,8 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private onSync = (syncState: SyncState, oldSyncState?: SyncState, data?: ISyncStateData): void => {
|
private onSync = (syncState: SyncState, oldSyncState?: SyncState, data?: ISyncStateData): void => {
|
||||||
const oldErrCode = this.state.syncErrorData?.error?.errcode;
|
const oldErrCode = (this.state.syncErrorData?.error as MatrixError)?.errcode;
|
||||||
const newErrCode = data && data.error && data.error.errcode;
|
const newErrCode = (data?.error as MatrixError)?.errcode;
|
||||||
if (syncState === oldSyncState && oldErrCode === newErrCode) return;
|
if (syncState === oldSyncState && oldErrCode === newErrCode) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -317,9 +318,9 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private calculateServerLimitToast(syncError: IState["syncErrorData"], usageLimitEventContent?: IUsageLimit) {
|
private calculateServerLimitToast(syncError: IState["syncErrorData"], usageLimitEventContent?: IUsageLimit) {
|
||||||
const error = syncError && syncError.error && syncError.error.errcode === "M_RESOURCE_LIMIT_EXCEEDED";
|
const error = (syncError?.error as MatrixError)?.errcode === "M_RESOURCE_LIMIT_EXCEEDED";
|
||||||
if (error) {
|
if (error) {
|
||||||
usageLimitEventContent = syncError.error.data as IUsageLimit;
|
usageLimitEventContent = (syncError?.error as MatrixError).data as IUsageLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// usageLimitDismissed is true when the user has explicitly hidden the toast
|
// usageLimitDismissed is true when the user has explicitly hidden the toast
|
||||||
|
|
|
@ -24,7 +24,6 @@ import {
|
||||||
MatrixEventEvent,
|
MatrixEventEvent,
|
||||||
} from 'matrix-js-sdk/src/matrix';
|
} from 'matrix-js-sdk/src/matrix';
|
||||||
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
|
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
|
||||||
import { MatrixError } from 'matrix-js-sdk/src/http-api';
|
|
||||||
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
|
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
|
||||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import { defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils";
|
import { defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils";
|
||||||
|
@ -203,7 +202,7 @@ interface IState {
|
||||||
// When showing Modal dialogs we need to set aria-hidden on the root app element
|
// When showing Modal dialogs we need to set aria-hidden on the root app element
|
||||||
// and disable it when there are no dialogs
|
// and disable it when there are no dialogs
|
||||||
hideToSRUsers: boolean;
|
hideToSRUsers: boolean;
|
||||||
syncError?: MatrixError;
|
syncError?: Error;
|
||||||
resizeNotifier: ResizeNotifier;
|
resizeNotifier: ResizeNotifier;
|
||||||
serverConfig?: ValidatedServerConfig;
|
serverConfig?: ValidatedServerConfig;
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
|
@ -1457,7 +1456,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
if (data.error instanceof InvalidStoreError) {
|
if (data.error instanceof InvalidStoreError) {
|
||||||
Lifecycle.handleInvalidStoreError(data.error);
|
Lifecycle.handleInvalidStoreError(data.error);
|
||||||
}
|
}
|
||||||
this.setState({ syncError: data.error || {} as MatrixError });
|
this.setState({ syncError: data.error });
|
||||||
} else if (this.state.syncError) {
|
} else if (this.state.syncError) {
|
||||||
this.setState({ syncError: null });
|
this.setState({ syncError: null });
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,8 @@ export function messageForResourceLimitError(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function messageForSyncError(err: MatrixError): ReactNode {
|
export function messageForSyncError(err: Error): ReactNode {
|
||||||
if (err.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
|
if (err instanceof MatrixError && err.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
|
||||||
const limitError = messageForResourceLimitError(
|
const limitError = messageForResourceLimitError(
|
||||||
err.data.limit_type,
|
err.data.limit_type,
|
||||||
err.data.admin_contact,
|
err.data.admin_contact,
|
||||||
|
|
Loading…
Reference in a new issue