Make more code conform to strict null checks (#10219
* Make more code conform to strict null checks * Fix types * Fix tests * Fix remaining test assertions * Iterate PR
This commit is contained in:
parent
4c79ecf141
commit
76b82b4b2b
130 changed files with 603 additions and 603 deletions
|
@ -65,7 +65,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
"src",
|
||||
`https://www.recaptcha.net/recaptcha/api.js?onload=mxOnRecaptchaLoaded&render=explicit`,
|
||||
);
|
||||
this.recaptchaContainer.current.appendChild(scriptTag);
|
||||
this.recaptchaContainer.current?.appendChild(scriptTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
}
|
||||
|
||||
logger.info("Rendering to %s", divId);
|
||||
this.captchaWidgetId = global.grecaptcha.render(divId, {
|
||||
this.captchaWidgetId = global.grecaptcha?.render(divId, {
|
||||
sitekey: publicKey,
|
||||
callback: this.props.onCaptchaResponse,
|
||||
});
|
||||
|
@ -113,7 +113,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
this.renderRecaptcha(DIV_ID);
|
||||
// clear error if re-rendered
|
||||
this.setState({
|
||||
errorText: null,
|
||||
errorText: undefined,
|
||||
});
|
||||
} catch (e) {
|
||||
this.setState({
|
||||
|
@ -123,7 +123,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
let error = null;
|
||||
let error: JSX.Element | undefined;
|
||||
if (this.state.errorText) {
|
||||
error = <div className="error">{this.state.errorText}</div>;
|
||||
}
|
||||
|
|
|
@ -50,12 +50,12 @@ class EmailField extends PureComponent<IProps> {
|
|||
{
|
||||
key: "required",
|
||||
test: ({ value, allowEmpty }) => allowEmpty || !!value,
|
||||
invalid: () => _t(this.props.labelRequired),
|
||||
invalid: () => _t(this.props.labelRequired!),
|
||||
},
|
||||
{
|
||||
key: "email",
|
||||
test: ({ value }) => !value || Email.looksValid(value),
|
||||
invalid: () => _t(this.props.labelInvalid),
|
||||
invalid: () => _t(this.props.labelInvalid!),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -80,7 +80,7 @@ class EmailField extends PureComponent<IProps> {
|
|||
id={this.props.id}
|
||||
ref={this.props.fieldRef}
|
||||
type="text"
|
||||
label={_t(this.props.label)}
|
||||
label={_t(this.props.label!)}
|
||||
value={this.props.value}
|
||||
autoFocus={this.props.autoFocus}
|
||||
onChange={this.props.onChange}
|
||||
|
|
|
@ -36,7 +36,7 @@ interface IProps {
|
|||
phoneNumber: string;
|
||||
|
||||
serverConfig: ValidatedServerConfig;
|
||||
loginIncorrect?: boolean;
|
||||
loginIncorrect: boolean;
|
||||
disableSubmit?: boolean;
|
||||
busy?: boolean;
|
||||
|
||||
|
@ -67,9 +67,9 @@ const enum LoginField {
|
|||
* The email/username/phone fields are fully-controlled, the password field is not.
|
||||
*/
|
||||
export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
||||
private [LoginField.Email]: Field;
|
||||
private [LoginField.Phone]: Field;
|
||||
private [LoginField.MatrixId]: Field;
|
||||
private [LoginField.Email]: Field | null;
|
||||
private [LoginField.Phone]: Field | null;
|
||||
private [LoginField.MatrixId]: Field | null;
|
||||
|
||||
public static defaultProps = {
|
||||
onUsernameChanged: function () {},
|
||||
|
@ -93,7 +93,7 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
private onForgotPasswordClick = (ev: ButtonEvent): void => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this.props.onForgotPasswordClick();
|
||||
this.props.onForgotPasswordClick?.();
|
||||
};
|
||||
|
||||
private onSubmitForm = async (ev: SyntheticEvent): Promise<void> => {
|
||||
|
@ -116,25 +116,25 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
};
|
||||
|
||||
private onUsernameChanged = (ev: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
this.props.onUsernameChanged(ev.target.value);
|
||||
this.props.onUsernameChanged?.(ev.target.value);
|
||||
};
|
||||
|
||||
private onUsernameBlur = (ev: React.FocusEvent<HTMLInputElement>): void => {
|
||||
this.props.onUsernameBlur(ev.target.value);
|
||||
this.props.onUsernameBlur?.(ev.target.value);
|
||||
};
|
||||
|
||||
private onLoginTypeChange = (ev: React.ChangeEvent<HTMLSelectElement>): void => {
|
||||
const loginType = ev.target.value as IState["loginType"];
|
||||
this.setState({ loginType });
|
||||
this.props.onUsernameChanged(""); // Reset because email and username use the same state
|
||||
this.props.onUsernameChanged?.(""); // Reset because email and username use the same state
|
||||
};
|
||||
|
||||
private onPhoneCountryChanged = (country: PhoneNumberCountryDefinition): void => {
|
||||
this.props.onPhoneCountryChanged(country.iso2);
|
||||
this.props.onPhoneCountryChanged?.(country.iso2);
|
||||
};
|
||||
|
||||
private onPhoneNumberChanged = (ev: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
this.props.onPhoneNumberChanged(ev.target.value);
|
||||
this.props.onPhoneNumberChanged?.(ev.target.value);
|
||||
};
|
||||
|
||||
private onPasswordChanged = (ev: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
|
@ -199,7 +199,7 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private markFieldValid(fieldID: LoginField, valid: boolean): void {
|
||||
private markFieldValid(fieldID: LoginField, valid?: boolean): void {
|
||||
const { fieldValid } = this.state;
|
||||
fieldValid[fieldID] = valid;
|
||||
this.setState({
|
||||
|
@ -368,7 +368,7 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
let forgotPasswordJsx;
|
||||
let forgotPasswordJsx: JSX.Element | undefined;
|
||||
|
||||
if (this.props.onForgotPasswordClick) {
|
||||
forgotPasswordJsx = (
|
||||
|
|
|
@ -34,7 +34,7 @@ interface IProps {}
|
|||
export default class Welcome extends React.PureComponent<IProps> {
|
||||
public render(): React.ReactNode {
|
||||
const pagesConfig = SdkConfig.getObject("embedded_pages");
|
||||
let pageUrl = null;
|
||||
let pageUrl!: string;
|
||||
if (pagesConfig) {
|
||||
pageUrl = pagesConfig.get("welcome_url");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue