Comply with noImplicitAny (#9940)
* Stash noImplicitAny work * Stash * Fix imports * Iterate * Fix tests * Delint * Fix tests
This commit is contained in:
parent
ac7f69216e
commit
61a63e47f4
359 changed files with 1621 additions and 1353 deletions
|
@ -37,7 +37,7 @@ import SSOButtons from "../../views/elements/SSOButtons";
|
|||
import ServerPicker from "../../views/elements/ServerPicker";
|
||||
import AuthBody from "../../views/auth/AuthBody";
|
||||
import AuthHeader from "../../views/auth/AuthHeader";
|
||||
import AccessibleButton from "../../views/elements/AccessibleButton";
|
||||
import AccessibleButton, { ButtonEvent } from "../../views/elements/AccessibleButton";
|
||||
import { ValidatedServerConfig } from "../../../utils/ValidatedServerConfig";
|
||||
|
||||
// These are used in several places, and come from the js-sdk's autodiscovery
|
||||
|
@ -101,6 +101,11 @@ interface IState {
|
|||
serverDeadError?: ReactNode;
|
||||
}
|
||||
|
||||
type OnPasswordLogin = {
|
||||
(username: string, phoneCountry: undefined, phoneNumber: undefined, password: string): Promise<void>;
|
||||
(username: undefined, phoneCountry: string, phoneNumber: string, password: string): Promise<void>;
|
||||
};
|
||||
|
||||
/*
|
||||
* A wire component which glues together login UI components and Login logic
|
||||
*/
|
||||
|
@ -110,7 +115,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
|
||||
private readonly stepRendererMap: Record<string, () => ReactNode>;
|
||||
|
||||
public constructor(props) {
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
|
@ -152,7 +157,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
this.unmounted = true;
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps): void {
|
||||
public componentDidUpdate(prevProps: IProps): void {
|
||||
if (
|
||||
prevProps.serverConfig.hsUrl !== this.props.serverConfig.hsUrl ||
|
||||
prevProps.serverConfig.isUrl !== this.props.serverConfig.isUrl
|
||||
|
@ -164,7 +169,12 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
|
||||
public isBusy = (): boolean => this.state.busy || this.props.busy;
|
||||
|
||||
public onPasswordLogin = async (username, phoneCountry, phoneNumber, password): Promise<void> => {
|
||||
public onPasswordLogin: OnPasswordLogin = async (
|
||||
username: string | undefined,
|
||||
phoneCountry: string | undefined,
|
||||
phoneNumber: string | undefined,
|
||||
password: string,
|
||||
): Promise<void> => {
|
||||
if (!this.state.serverIsAlive) {
|
||||
this.setState({ busy: true });
|
||||
// Do a quick liveliness check on the URLs
|
||||
|
@ -207,10 +217,10 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
if (this.unmounted) {
|
||||
return;
|
||||
}
|
||||
let errorText;
|
||||
let errorText: ReactNode;
|
||||
|
||||
// Some error strings only apply for logging in
|
||||
const usingEmail = username.indexOf("@") > 0;
|
||||
const usingEmail = username?.indexOf("@") > 0;
|
||||
if (error.httpStatus === 400 && usingEmail) {
|
||||
errorText = _t("This homeserver does not support login using email address.");
|
||||
} else if (error.errcode === "M_RESOURCE_LIMIT_EXCEEDED") {
|
||||
|
@ -264,11 +274,11 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
);
|
||||
};
|
||||
|
||||
public onUsernameChanged = (username): void => {
|
||||
this.setState({ username: username });
|
||||
public onUsernameChanged = (username: string): void => {
|
||||
this.setState({ username });
|
||||
};
|
||||
|
||||
public onUsernameBlur = async (username): Promise<void> => {
|
||||
public onUsernameBlur = async (username: string): Promise<void> => {
|
||||
const doWellknownLookup = username[0] === "@";
|
||||
this.setState({
|
||||
username: username,
|
||||
|
@ -315,23 +325,21 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
}
|
||||
};
|
||||
|
||||
public onPhoneCountryChanged = (phoneCountry): void => {
|
||||
this.setState({ phoneCountry: phoneCountry });
|
||||
public onPhoneCountryChanged = (phoneCountry: string): void => {
|
||||
this.setState({ phoneCountry });
|
||||
};
|
||||
|
||||
public onPhoneNumberChanged = (phoneNumber): void => {
|
||||
this.setState({
|
||||
phoneNumber: phoneNumber,
|
||||
});
|
||||
public onPhoneNumberChanged = (phoneNumber: string): void => {
|
||||
this.setState({ phoneNumber });
|
||||
};
|
||||
|
||||
public onRegisterClick = (ev): void => {
|
||||
public onRegisterClick = (ev: ButtonEvent): void => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this.props.onRegisterClick();
|
||||
};
|
||||
|
||||
public onTryRegisterClick = (ev): void => {
|
||||
public onTryRegisterClick = (ev: ButtonEvent): void => {
|
||||
const hasPasswordFlow = this.state.flows?.find((flow) => flow.type === "m.login.password");
|
||||
const ssoFlow = this.state.flows?.find((flow) => flow.type === "m.login.sso" || flow.type === "m.login.cas");
|
||||
// If has no password flow but an SSO flow guess that the user wants to register with SSO.
|
||||
|
@ -540,7 +548,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
|
|||
);
|
||||
};
|
||||
|
||||
private renderSsoStep = (loginType): JSX.Element => {
|
||||
private renderSsoStep = (loginType: "cas" | "sso"): JSX.Element => {
|
||||
const flow = this.state.flows.find((flow) => flow.type === "m.login." + loginType) as ISSOFlow;
|
||||
|
||||
return (
|
||||
|
|
|
@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { AuthType, createClient, IAuthData, IInputs } from "matrix-js-sdk/src/matrix";
|
||||
import { AuthType, createClient, IAuthData, IInputs, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
import React, { Fragment, ReactNode } from "react";
|
||||
import { IRequestTokenResponse, MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { IRegisterRequestParams, IRequestTokenResponse, MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import classNames from "classnames";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ISSOFlow, SSOAction } from "matrix-js-sdk/src/@types/auth";
|
||||
|
@ -125,7 +125,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
// `replaceClient` tracks latest serverConfig to spot when it changes under the async method which fetches flows
|
||||
private latestServerConfig: ValidatedServerConfig;
|
||||
|
||||
public constructor(props) {
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
|
@ -166,7 +166,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
}
|
||||
};
|
||||
|
||||
public componentDidUpdate(prevProps): void {
|
||||
public componentDidUpdate(prevProps: IProps): void {
|
||||
if (
|
||||
prevProps.serverConfig.hsUrl !== this.props.serverConfig.hsUrl ||
|
||||
prevProps.serverConfig.isUrl !== this.props.serverConfig.isUrl
|
||||
|
@ -307,7 +307,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
if (!success) {
|
||||
let errorText: ReactNode = (response as Error).message || (response as Error).toString();
|
||||
// can we give a better error message?
|
||||
if (response.errcode === "M_RESOURCE_LIMIT_EXCEEDED") {
|
||||
if (response instanceof MatrixError && response.errcode === "M_RESOURCE_LIMIT_EXCEEDED") {
|
||||
const errorTop = messageForResourceLimitError(response.data.limit_type, response.data.admin_contact, {
|
||||
"monthly_active_user": _td("This homeserver has hit its Monthly Active User limit."),
|
||||
"hs_blocked": _td("This homeserver has been blocked by its administrator."),
|
||||
|
@ -326,17 +326,17 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
<p>{errorDetail}</p>
|
||||
</div>
|
||||
);
|
||||
} else if (response.required_stages && response.required_stages.includes(AuthType.Msisdn)) {
|
||||
} else if ((response as IAuthData).required_stages?.includes(AuthType.Msisdn)) {
|
||||
let msisdnAvailable = false;
|
||||
for (const flow of response.available_flows) {
|
||||
for (const flow of (response as IAuthData).available_flows) {
|
||||
msisdnAvailable = msisdnAvailable || flow.stages.includes(AuthType.Msisdn);
|
||||
}
|
||||
if (!msisdnAvailable) {
|
||||
errorText = _t("This server does not support authentication with a phone number.");
|
||||
}
|
||||
} else if (response.errcode === "M_USER_IN_USE") {
|
||||
} else if (response instanceof MatrixError && response.errcode === "M_USER_IN_USE") {
|
||||
errorText = _t("Someone already has that username, please try another.");
|
||||
} else if (response.errcode === "M_THREEPID_IN_USE") {
|
||||
} else if (response instanceof MatrixError && response.errcode === "M_THREEPID_IN_USE") {
|
||||
errorText = _t("That e-mail address or phone number is already in use.");
|
||||
}
|
||||
|
||||
|
@ -348,11 +348,11 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
return;
|
||||
}
|
||||
|
||||
MatrixClientPeg.setJustRegisteredUserId(response.user_id);
|
||||
MatrixClientPeg.setJustRegisteredUserId((response as IAuthData).user_id);
|
||||
|
||||
const newState = {
|
||||
const newState: Partial<IState> = {
|
||||
doingUIAuth: false,
|
||||
registeredUsername: response.user_id,
|
||||
registeredUsername: (response as IAuthData).user_id,
|
||||
differentLoggedInUserId: null,
|
||||
completedNoSignin: false,
|
||||
// we're still busy until we get unmounted: don't show the registration form again
|
||||
|
@ -365,8 +365,10 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
// starting the registration process. This isn't perfect since it's possible
|
||||
// the user had a separate guest session they didn't actually mean to replace.
|
||||
const [sessionOwner, sessionIsGuest] = await Lifecycle.getStoredSessionOwner();
|
||||
if (sessionOwner && !sessionIsGuest && sessionOwner !== response.user_id) {
|
||||
logger.log(`Found a session for ${sessionOwner} but ${response.user_id} has just registered.`);
|
||||
if (sessionOwner && !sessionIsGuest && sessionOwner !== (response as IAuthData).user_id) {
|
||||
logger.log(
|
||||
`Found a session for ${sessionOwner} but ${(response as IAuthData).user_id} has just registered.`,
|
||||
);
|
||||
newState.differentLoggedInUserId = sessionOwner;
|
||||
}
|
||||
|
||||
|
@ -383,7 +385,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
// as the client that started registration may be gone by the time we've verified the email, and only the client
|
||||
// that verified the email is guaranteed to exist, we'll always do the login in that client.
|
||||
const hasEmail = Boolean(this.state.formVals.email);
|
||||
const hasAccessToken = Boolean(response.access_token);
|
||||
const hasAccessToken = Boolean((response as IAuthData).access_token);
|
||||
debuglog("Registration: ui auth finished:", { hasEmail, hasAccessToken });
|
||||
// don’t log in if we found a session for a different user
|
||||
if (!hasEmail && hasAccessToken && !newState.differentLoggedInUserId) {
|
||||
|
@ -391,11 +393,11 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
// the email, not the client that started the registration flow
|
||||
await this.props.onLoggedIn(
|
||||
{
|
||||
userId: response.user_id,
|
||||
deviceId: response.device_id,
|
||||
userId: (response as IAuthData).user_id,
|
||||
deviceId: (response as IAuthData).device_id,
|
||||
homeserverUrl: this.state.matrixClient.getHomeserverUrl(),
|
||||
identityServerUrl: this.state.matrixClient.getIdentityServerUrl(),
|
||||
accessToken: response.access_token,
|
||||
accessToken: (response as IAuthData).access_token,
|
||||
},
|
||||
this.state.formVals.password,
|
||||
);
|
||||
|
@ -406,7 +408,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
newState.completedNoSignin = true;
|
||||
}
|
||||
|
||||
this.setState(newState);
|
||||
this.setState(newState as IState);
|
||||
};
|
||||
|
||||
private setupPushers(): Promise<void> {
|
||||
|
@ -455,7 +457,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||
};
|
||||
|
||||
private makeRegisterRequest = (auth: IAuthData | null): Promise<IAuthData> => {
|
||||
const registerParams = {
|
||||
const registerParams: IRegisterRequestParams = {
|
||||
username: this.state.formVals.username,
|
||||
password: this.state.formVals.password,
|
||||
initial_device_display_name: this.props.defaultDeviceDisplayName,
|
||||
|
|
|
@ -45,7 +45,7 @@ interface IState {
|
|||
}
|
||||
|
||||
export default class SetupEncryptionBody extends React.Component<IProps, IState> {
|
||||
public constructor(props) {
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
const store = SetupEncryptionStore.sharedInstance();
|
||||
store.on("update", this.onStoreUpdate);
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import React, { ChangeEvent, SyntheticEvent } from "react";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { Optional } from "matrix-events-sdk";
|
||||
import { ISSOFlow, LoginFlow, SSOAction } from "matrix-js-sdk/src/@types/auth";
|
||||
|
@ -44,7 +44,7 @@ enum LoginView {
|
|||
Unsupported,
|
||||
}
|
||||
|
||||
const STATIC_FLOWS_TO_VIEWS = {
|
||||
const STATIC_FLOWS_TO_VIEWS: Record<string, LoginView> = {
|
||||
"m.login.password": LoginView.Password,
|
||||
"m.login.cas": LoginView.CAS,
|
||||
"m.login.sso": LoginView.SSO,
|
||||
|
@ -133,7 +133,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
|||
this.setState({ flows, loginView: chosenView });
|
||||
}
|
||||
|
||||
private onPasswordChange = (ev): void => {
|
||||
private onPasswordChange = (ev: ChangeEvent<HTMLInputElement>): void => {
|
||||
this.setState({ password: ev.target.value });
|
||||
};
|
||||
|
||||
|
@ -141,7 +141,7 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
|||
dis.dispatch({ action: "start_password_recovery" });
|
||||
};
|
||||
|
||||
private onPasswordLogin = async (ev): Promise<void> => {
|
||||
private onPasswordLogin = async (ev: SyntheticEvent): Promise<void> => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue