Implemented strict mode for the project (broken tests, hundreds of @ts-ignore and new errors are included) [skip ci]

This commit is contained in:
ErickSkrauch
2020-01-17 23:37:52 +03:00
committed by SleepWalker
parent 10e8b77acf
commit 96049ad4ad
151 changed files with 2470 additions and 1869 deletions

View File

@@ -1,16 +1,14 @@
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import React, { useState, useEffect, ComponentType } from 'react';
import { useSelector } from 'react-redux';
import { RawIntlProvider, IntlShape } from 'react-intl';
import i18n from 'app/services/i18n';
import { RootState } from 'app/reducers';
type Props = {
children: React.ReactNode;
locale: string;
};
function IntlProvider({ children, locale }: Props) {
const IntlProvider: ComponentType = ({ children }) => {
const [intl, setIntl] = useState<IntlShape>(i18n.getIntl());
const locale = useSelector(
({ i18n: i18nState }: RootState) => i18nState.locale,
);
useEffect(() => {
(async () => {
@@ -19,8 +17,6 @@ function IntlProvider({ children, locale }: Props) {
}, [locale]);
return <RawIntlProvider value={intl}>{children}</RawIntlProvider>;
}
};
export default connect(({ i18n: i18nState }: RootState) => i18nState)(
IntlProvider,
);
export default IntlProvider;

View File

@@ -1,10 +1,9 @@
import { Action as ReduxAction } from 'redux';
import i18n from 'app/services/i18n';
import { ThunkAction } from 'app/reducers';
export const SET_LOCALE = 'i18n:setLocale';
export function setLocale(desiredLocale: string) {
return async (
dispatch: (action: { [key: string]: any }) => any,
): Promise<string> => {
export function setLocale(desiredLocale: string): ThunkAction<Promise<string>> {
return async dispatch => {
const locale = i18n.detectLanguage(desiredLocale);
dispatch(_setLocale(locale));
@@ -13,11 +12,20 @@ export function setLocale(desiredLocale: string) {
};
}
function _setLocale(locale: string) {
interface SetAction extends ReduxAction {
type: 'i18n:setLocale';
payload: {
locale: string;
};
}
function _setLocale(locale: string): SetAction {
return {
type: SET_LOCALE,
type: 'i18n:setLocale',
payload: {
locale,
},
};
}
export type Action = SetAction;

View File

@@ -1,6 +1,6 @@
import supportedLocales from 'app/i18n';
const localeToCountryCode = {
const localeToCountryCode: Record<string, string> = {
en: 'gb',
be: 'by',
pt: 'br',

View File

@@ -1,18 +1,20 @@
import i18n from 'app/services/i18n';
import { SET_LOCALE } from './actions';
import { Action } from './actions';
export type State = { locale: string };
export interface State {
locale: string;
}
const defaultState = {
const defaultState: State = {
locale: i18n.detectLanguage(),
};
export default function(
state: State = defaultState,
{ type, payload }: { type: string; payload: State },
{ type, payload }: Action,
): State {
if (type === SET_LOCALE) {
if (type === 'i18n:setLocale') {
return payload;
}