Upgrade ts to the latest version and fix type errors

This commit is contained in:
SleepWalker
2020-05-20 19:59:06 +03:00
parent 2d903f96fc
commit 29326519b8
16 changed files with 37 additions and 37 deletions

View File

@ -163,7 +163,7 @@
"speed-measure-webpack-plugin": "^1.3.3", "speed-measure-webpack-plugin": "^1.3.3",
"storybook-addon-intl": "^2.4.1", "storybook-addon-intl": "^2.4.1",
"style-loader": "~1.2.1", "style-loader": "~1.2.1",
"typescript": "^3.7.4", "typescript": "^3.9.3",
"unexpected": "^11.14.0", "unexpected": "^11.14.0",
"unexpected-sinon": "^10.5.1", "unexpected-sinon": "^10.5.1",
"url-loader": "^4.1.0", "url-loader": "^4.1.0",

View File

@ -169,7 +169,7 @@ export class AccountSwitcher extends React.Component<Props> {
); );
} }
onSwitch = (account: Account) => (event: React.MouseEvent) => { onSwitch = (account: Account) => (event: React.MouseEvent<any>) => {
event.preventDefault(); event.preventDefault();
loader.show(); loader.show();
@ -184,7 +184,7 @@ export class AccountSwitcher extends React.Component<Props> {
.finally(() => loader.hide()); .finally(() => loader.hide());
}; };
onRemove = (account: Account) => (event: React.MouseEvent) => { onRemove = (account: Account) => (event: React.MouseEvent<any>) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

View File

@ -406,7 +406,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
}); });
}; };
onGoBack: MouseEventHandler = (event): void => { onGoBack: MouseEventHandler<HTMLButtonElement> = (event): void => {
event.preventDefault(); event.preventDefault();
authFlow.goBack(); authFlow.goBack();
}; };

View File

@ -680,7 +680,7 @@ function validationErrorsHandler(
repeatUrl?: string, repeatUrl?: string,
): ( ): (
resp: Resp<{ resp: Resp<{
errors?: Record<string, string>; errors?: Record<string, string | ValidationError>;
data?: Record<string, any>; data?: Record<string, any>;
}>, }>,
) => Promise<never> { ) => Promise<never> {

View File

@ -11,7 +11,9 @@ import messages from './footerMenu.intl.json';
const FooterMenu: ComponentType = () => { const FooterMenu: ComponentType = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const onLanguageSwitcherClick = useCallback<MouseEventHandler>( const onLanguageSwitcherClick = useCallback<
MouseEventHandler<HTMLAnchorElement>
>(
(event) => { (event) => {
event.preventDefault(); event.preventDefault();
dispatch(createPopup({ Popup: LanguageSwitcher })); dispatch(createPopup({ Popup: LanguageSwitcher }));

View File

@ -124,7 +124,7 @@ export default class LanguageList extends React.Component<{
return emptyCaptions[Math.floor(Math.random() * emptyCaptions.length)]; return emptyCaptions[Math.floor(Math.random() * emptyCaptions.length)];
} }
onChangeLang(lang: string): MouseEventHandler { onChangeLang(lang: string): MouseEventHandler<HTMLDivElement> {
return (event) => { return (event) => {
event.preventDefault(); event.preventDefault();

View File

@ -313,7 +313,7 @@ export default class ChangeEmail extends React.Component<Props, State> {
return this.state.activeStep + 1 === STEPS_TOTAL; return this.state.activeStep + 1 === STEPS_TOTAL;
} }
onSwitchStep = (event: React.MouseEvent) => { onSwitchStep = (event: React.MouseEvent<HTMLAnchorElement>) => {
event.preventDefault(); event.preventDefault();
this.nextStep(); this.nextStep();

View File

@ -103,7 +103,7 @@ export class PanelBodyHeader extends React.Component<
); );
} }
onClose = (event: React.MouseEvent) => { onClose = (event: React.MouseEvent<HTMLElement>) => {
event.preventDefault(); event.preventDefault();
const { onClose } = this.props; const { onClose } = this.props;

View File

@ -100,7 +100,7 @@ export default class Dropdown extends FormInputComponent<Props, State> {
}); });
} }
onSelectItem(item: OptionItem): MouseEventHandler { onSelectItem(item: OptionItem): MouseEventHandler<HTMLDivElement> {
return (event) => { return (event) => {
event.preventDefault(); event.preventDefault();

View File

@ -3,16 +3,16 @@ import { Link } from 'react-router-dom';
import Button from './Button'; import Button from './Button';
export default function LinkButton( type ButtonProps = React.ComponentProps<typeof Button>;
props: React.ComponentProps<typeof Button> & type LinkProps = React.ComponentProps<typeof Link>;
React.ComponentProps<typeof Link>,
) { export default function LinkButton(props: ButtonProps & LinkProps) {
const { to, ...restProps } = props; const { to, ...restProps } = props;
return ( return (
<Button <Button
component={(linkProps) => <Link {...linkProps} to={to} />} component={(linkProps) => <Link {...linkProps} to={to} />}
{...restProps} {...(restProps as ButtonProps)}
/> />
); );
} }

View File

@ -14,7 +14,7 @@ function DummyPopup(_props: Record<string, any>) {
describe('<PopupStack />', () => { describe('<PopupStack />', () => {
it('renders all popup components', () => { it('renders all popup components', () => {
const props = { const props: any = {
destroy: () => {}, destroy: () => {},
popups: [ popups: [
{ {
@ -35,13 +35,13 @@ describe('<PopupStack />', () => {
foo: 'bar', foo: 'bar',
}; };
const props = { const props: any = {
destroy: () => {}, destroy: () => {},
popups: [ popups: [
{ {
Popup: (props = { onClose: Function }) => { Popup: (popupProps = { onClose: Function }) => {
// eslint-disable-next-line // eslint-disable-next-line
expect(props.onClose, 'to be a', 'function'); expect(popupProps.onClose, 'to be a', 'function');
return <DummyPopup {...expectedProps} />; return <DummyPopup {...expectedProps} />;
}, },
@ -56,7 +56,7 @@ describe('<PopupStack />', () => {
}); });
it('should hide popup, when onClose called', () => { it('should hide popup, when onClose called', () => {
const props = { const props: any = {
popups: [ popups: [
{ {
Popup: DummyPopup, Popup: DummyPopup,
@ -79,7 +79,7 @@ describe('<PopupStack />', () => {
it('should hide popup, when overlay clicked', () => { it('should hide popup, when overlay clicked', () => {
const preventDefault = sinon.stub().named('event.preventDefault'); const preventDefault = sinon.stub().named('event.preventDefault');
const props = { const props: any = {
destroy: sinon.stub().named('props.destroy'), destroy: sinon.stub().named('props.destroy'),
popups: [ popups: [
{ {
@ -97,7 +97,7 @@ describe('<PopupStack />', () => {
}); });
it('should hide popup on overlay click if disableOverlayClose', () => { it('should hide popup on overlay click if disableOverlayClose', () => {
const props = { const props: any = {
destroy: sinon.stub().named('props.destroy'), destroy: sinon.stub().named('props.destroy'),
popups: [ popups: [
{ {
@ -119,7 +119,7 @@ describe('<PopupStack />', () => {
}); });
it('should hide popup, when esc pressed', () => { it('should hide popup, when esc pressed', () => {
const props = { const props: any = {
destroy: sinon.stub().named('props.destroy'), destroy: sinon.stub().named('props.destroy'),
popups: [ popups: [
{ {
@ -138,7 +138,7 @@ describe('<PopupStack />', () => {
}); });
it('should hide first popup in stack if esc pressed', () => { it('should hide first popup in stack if esc pressed', () => {
const props = { const props: any = {
destroy: sinon.stub().named('props.destroy'), destroy: sinon.stub().named('props.destroy'),
popups: [ popups: [
{ {
@ -165,7 +165,7 @@ describe('<PopupStack />', () => {
}); });
it('should NOT hide popup on esc pressed if disableOverlayClose', () => { it('should NOT hide popup on esc pressed if disableOverlayClose', () => {
const props = { const props: any = {
destroy: sinon.stub().named('props.destroy'), destroy: sinon.stub().named('props.destroy'),
popups: [ popups: [
{ {

View File

@ -64,7 +64,7 @@ export class PopupStack extends React.Component<Props> {
} }
onOverlayClick(popup: PopupConfig) { onOverlayClick(popup: PopupConfig) {
return (event: React.MouseEvent) => { return (event: React.MouseEvent<HTMLDivElement>) => {
if (event.target !== event.currentTarget || popup.disableOverlayClose) { if (event.target !== event.currentTarget || popup.disableOverlayClose) {
return; return;
} }

View File

@ -77,7 +77,7 @@ export default class AuthFlow implements AuthContext {
replace: ((path: string) => void) | null; replace: ((path: string) => void) | null;
onReady: () => void; onReady: () => void;
navigate: (route: string, options: { replace?: boolean }) => void; navigate: (route: string, options: { replace?: boolean }) => void;
currentRequest: Request; currentRequest: Partial<Request> = {};
oAuthStateRestored = false; oAuthStateRestored = false;
dispatch: (action: Record<string, any>) => void; dispatch: (action: Record<string, any>) => void;
getState: () => RootState; getState: () => RootState;

View File

@ -8,12 +8,9 @@ export const SUPPORTED_LANGUAGES = Object.keys(locales);
export const DEFAULT_LANGUAGE = 'en'; export const DEFAULT_LANGUAGE = 'en';
function getBrowserPreferredLanguages(): string[] { function getBrowserPreferredLanguages(): string[] {
return [] return ([] as string[])
.concat( .concat(navigator['languages'] || [])
// @ts-ignore .concat(navigator['language'] || []);
navigator.languages || [],
)
.concat(navigator.language || []);
} }
function detectLanguage( function detectLanguage(

View File

@ -11,6 +11,7 @@
"noEmit": true, "noEmit": true,
"checkJs": true, "checkJs": true,
"allowJs": true, "allowJs": true,
"skipLibCheck": true,
"strictNullChecks": true, "strictNullChecks": true,
"strictPropertyInitialization": false, "strictPropertyInitialization": false,
"isolatedModules": true, "isolatedModules": true,

View File

@ -15665,10 +15665,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
typescript@^3.7.4: typescript@^3.9.3:
version "3.7.4" version "3.9.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.3.tgz#d3ac8883a97c26139e42df5e93eeece33d610b8a"
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw== integrity sha512-D/wqnB2xzNFIcoBG9FG8cXRDjiqSTbG2wd8DMZeQyJlP1vfTkIxH4GKveWaEBYySKIg+USu+E+EDIR47SqnaMQ==
ua-parser-js@^0.7.18: ua-parser-js@^0.7.18:
version "0.7.21" version "0.7.21"