1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-17 00:25:50 +07:00

fix: improved typing (#174)

This commit is contained in:
Thomas Klein
2019-10-10 22:20:05 +02:00
committed by Juan Picado @jotadeveloper
parent 68b7171de4
commit e0642a9d0d
16 changed files with 37 additions and 30 deletions

View File

@@ -1,27 +1,27 @@
import React from 'react';
import { mount } from 'enzyme';
import { mount, ReactWrapper } from 'enzyme';
import storage from '../utils/storage';
import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__/token';
import App from './App';
import App, { AppStateInterface } from './App';
jest.mock('../utils/storage', () => {
class LocalStorageMock {
private store: object;
private store: Record<string, string>;
public constructor() {
this.store = {};
}
public clear(): void {
this.store = {};
}
public getItem(key): unknown {
public getItem(key: string): unknown {
return this.store[key] || null;
}
public setItem(key, value): void {
public setItem(key: string, value: string): void {
this.store[key] = value.toString();
}
public removeItem(key): void {
public removeItem(key: string): void {
delete this.store[key];
}
}
@@ -33,7 +33,7 @@ jest.mock('../utils/api', () => ({
}));
describe('App', () => {
let wrapper;
let wrapper: ReactWrapper<{}, AppStateInterface, App>;
beforeEach(() => {
wrapper = mount(<App />);

View File

@@ -48,7 +48,7 @@ export default class App extends Component<{}, AppStateInterface> {
}
// eslint-disable-next-line no-unused-vars
public componentDidUpdate(_, prevState): void {
public componentDidUpdate(_: AppStateInterface, prevState: AppStateInterface): void {
const { isUserLoggedIn } = this.state;
if (prevState.isUserLoggedIn !== isUserLoggedIn) {
this.loadOnHandler();
@@ -99,7 +99,7 @@ export default class App extends Component<{}, AppStateInterface> {
}
};
public setLoading = isLoading =>
public setLoading = (isLoading: boolean) =>
this.setState({
isLoading,
});
@@ -118,7 +118,7 @@ export default class App extends Component<{}, AppStateInterface> {
* handles login
* Required by: <Header />
*/
public handleDoLogin = async (usernameValue, passwordValue) => {
public handleDoLogin = async (usernameValue: string, passwordValue: string) => {
const { username, token, error } = await makeLogin(usernameValue, passwordValue);
if (username && token) {
@@ -135,7 +135,7 @@ export default class App extends Component<{}, AppStateInterface> {
}
};
public setLoggedUser = username => {
public setLoggedUser = (username: string) => {
this.setState({
user: {
username,

View File

@@ -6,17 +6,17 @@ export interface ErrorProps {
export interface ErrorAppState {
hasError: boolean;
error: any;
info: any;
error: Error | null;
info: object | null;
}
export default class ErrorBoundary extends Component<ErrorProps, ErrorAppState> {
constructor(props) {
constructor(props: ErrorProps) {
super(props);
this.state = { hasError: false, error: null, info: null };
}
public componentDidCatch(error, info) {
public componentDidCatch(error: Error, info: object) {
this.setState({ hasError: true, error, info });
}