Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fix: improved typing (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkn authored and juanpicado committed Oct 10, 2019
1 parent 68b7171 commit e0642a9
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 30 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"scripts": {
"type-check": "tsc --noEmit --pretty",
"type-check:watch": "npm run type-check -- --watch",
"type-check-strict:watch": "tsc --project ./tsconfig.strict.json --noEmit --pretty --watch",
"release": "standard-version -a",
"test:clean": "npx jest --clearCache",
"test:acceptance": "codeceptjs run --steps",
Expand Down
14 changes: 7 additions & 7 deletions src/App/App.test.tsx
Original file line number Diff line number Diff line change
@@ -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];
}
}
Expand All @@ -33,7 +33,7 @@ jest.mock('../utils/api', () => ({
}));

describe('App', () => {
let wrapper;
let wrapper: ReactWrapper<{}, AppStateInterface, App>;

beforeEach(() => {
wrapper = mount(<App />);
Expand Down
8 changes: 4 additions & 4 deletions src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -99,7 +99,7 @@ export default class App extends Component<{}, AppStateInterface> {
}
};

public setLoading = isLoading =>
public setLoading = (isLoading: boolean) =>
this.setState({
isLoading,
});
Expand All @@ -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) {
Expand All @@ -135,7 +135,7 @@ export default class App extends Component<{}, AppStateInterface> {
}
};

public setLoggedUser = username => {
public setLoggedUser = (username: string) => {
this.setState({
user: {
username,
Expand Down
8 changes: 4 additions & 4 deletions src/App/AppError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarTooltip/AvatarTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AvatarDeveloper {

const AvatarTooltip: FC<AvatarDeveloper> = ({ name, packageName, version, avatar, email }) => {
const avatarComponent = <Avatar aria-label={name} src={avatar} />;
function renderLinkForMail(email, avatarComponent, packageName, version): JSX.Element {
function renderLinkForMail(email: string, avatarComponent: JSX.Element, packageName: string, version: string): JSX.Element {
if (!email || isEmail(email) === false) {
return avatarComponent;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CopyToClipBoard/CopyToClipBoard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { mount } from 'enzyme';
import { mount, ReactWrapper } from 'enzyme';

import CopyToClipBoard from './CopyToClipBoard';
import { CopyIcon } from './styles';

describe('<CopyToClipBoard /> component', () => {
let wrapper;
let wrapper: ReactWrapper;

beforeEach(() => {
wrapper = mount(<CopyToClipBoard text={'copy text'} />);
Expand Down
2 changes: 1 addition & 1 deletion src/components/CopyToClipBoard/CopyToClipBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {
children?: React.ReactNode;
}

const renderText = (text, children): JSX.Element => {
const renderText = (text: string, children: React.ReactNode): JSX.Element => {
if (children) {
return <ClipBoardCopyText>{children}</ClipBoardCopyText>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Engines/Engines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Engine extends Component {
return <Grid container={true}>{items}</Grid>;
};

private renderListItems = (heading, text) => {
private renderListItems = (heading: string, text: string) => {
return (
<List subheader={<Heading variant={'subtitle1'}>{text.split('-').join(' ')}</Heading>}>
<EngineListItem button={true}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Footer/Footer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { mount, ReactWrapper } from 'enzyme';

import Footer from './Footer';

Expand All @@ -8,7 +8,7 @@ jest.mock('../../../package.json', () => ({
}));

describe('<Footer /> component', () => {
let wrapper;
let wrapper: ReactWrapper;
beforeEach(() => {
window.VERDACCIO_VERSION = 'v.1.0.0';
wrapper = mount(<Footer />);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default class LoginModal extends Component<Partial<LoginModalProps>, Logi
});
};

public renderErrorMessage(title, description): JSX.Element {
public renderErrorMessage(title: string, description: string): JSX.Element {
return (
<span>
<div>
Expand All @@ -162,7 +162,7 @@ export default class LoginModal extends Component<Partial<LoginModalProps>, Logi
);
}

public renderMessage(title, description): JSX.Element {
public renderMessage(title: string, description: string): JSX.Element {
return (
<div className={classes.loginErrorMsg} id={'client-snackbar'}>
<ErrorIcon className={classes.loginIcon} />
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import App from './App';

const rootNode = document.getElementById('root');

const renderApp = (Component): void => {
const renderApp = (Component: React.ElementType): void => {
ReactDOM.render(
<AppContainer>
<Component />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Version/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getRouterPackageName(params): string {
return packageName;
}

function fillTitle(text): string {
function fillTitle(text: string): string {
return `Verdaccio - ${text}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PackageMetaInterface } from 'types/packageMeta';

import API from './api';

export async function callReadme(packageName, packageVersion?: string): Promise<string | {}> {
export async function callReadme(packageName: string, packageVersion?: string): Promise<string | {}> {
return await API.request<string | {}>(`package/readme/${packageName}${packageVersion ? `?v=${packageVersion}` : ''}`, 'GET');
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export function formatRepository(repository: any): string | null {
return null;
}

export function formatDate(lastUpdate): string {
export function formatDate(lastUpdate: string | number): string {
return format(new Date(lastUpdate), TIMEFORMAT);
}

export function formatDateDistance(lastUpdate): string {
export function formatDateDistance(lastUpdate: Date | string | number): string {
return distanceInWordsToNow(new Date(lastUpdate));
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function isURL(url: string): boolean {
});
}

export function isEmail(email): boolean {
export function isEmail(email: string): boolean {
return isEmailValidator(email || '');
}

Expand Down
6 changes: 6 additions & 0 deletions tsconfig.strict.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noImplicitAny": true
}
}

0 comments on commit e0642a9

Please sign in to comment.