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

Commit 116055c

Browse files
committed
fix: remove any types and added additional component state interfaces
1 parent 3c54b11 commit 116055c

File tree

11 files changed

+22
-21
lines changed

11 files changed

+22
-21
lines changed

jest/unit/components/__mocks__/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ const register = (url, method = 'get', options = {}) => {
3939
* Bind API methods
4040
*/
4141
class API {
42-
request() {
43-
return register.call(null, ...arguments);
42+
public request() {
43+
const rest = arguments;
44+
return register.call(null, ...rest);
4445
}
4546
}
4647

jest/unit/components/store/logo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* Mock response for logo api
33
* @returns {promise}
44
*/
5-
export default function() {
5+
export default function<T>(): Promise<T> {
66
return Promise.resolve('http://localhost/-/static/logo.png');
77
}

src/App/App.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__
77

88
jest.mock('../utils/storage', () => {
99
class LocalStorageMock {
10-
store: object;
10+
private store: object;
1111
public constructor() {
1212
this.store = {};
1313
}

src/App/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const AppContext = React.createContext<null>(null);
1919
export const AppContextProvider = AppContext.Provider;
2020
export const AppContextConsumer = AppContext.Consumer;
2121

22-
export default class App extends Component<any, any> {
22+
export default class App extends Component {
2323
public state = {
2424
error: {},
2525
// @ts-ignore

src/components/DetailContainer/DetailContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface DetailContainerState {
1414
tabPosition: number;
1515
}
1616

17-
class DetailContainer extends Component<any, DetailContainerState> {
17+
class DetailContainer<P> extends Component<P, DetailContainerState> {
1818
public state = {
1919
tabPosition: 0,
2020
};
@@ -29,7 +29,7 @@ class DetailContainer extends Component<any, DetailContainerState> {
2929
);
3030
}
3131

32-
private handleChange = (event: any, tabPosition: number) => {
32+
private handleChange = (event: React.ChangeEvent<{}>, tabPosition: number) => {
3333
event.preventDefault();
3434
this.setState({ tabPosition });
3535
};

src/components/RegistryInfoDialog/RegistryInfoDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Props } from './types';
88

99
const LABEL = 'CLOSE';
1010

11-
const RegistryInfoDialog: React.FC<Props> = ({ open = false, children, onClose }): any => (
11+
const RegistryInfoDialog: React.FC<Props> = ({ open = false, children, onClose }) => (
1212
<Dialog id="registryInfo--dialog-container" onClose={onClose} open={open}>
1313
<Title disableTypography={true}>{'Register Info'}</Title>
1414
<Content>{children}</Content>

src/components/Search/Search.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('<Search /> component test', () => {
154154
beforeEach(() => {
155155
jest.resetModules();
156156
jest.doMock('lodash/debounce', () => {
157-
return function debounceMock(fn, delay) {
157+
return function debounceMock(fn) {
158158
return fn;
159159
};
160160
});

src/pages/version/Version.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface StateInterface {
3939
notFound: boolean;
4040
}
4141

42-
class VersionPage extends Component<PropsInterface, StateInterface> {
42+
class VersionPage extends Component<PropsInterface, Partial<StateInterface>> {
4343
constructor(props) {
4444
super(props);
4545

@@ -81,7 +81,7 @@ class VersionPage extends Component<PropsInterface, StateInterface> {
8181
public async componentDidUpdate(nextProps, prevState: StateInterface): Promise<void> {
8282
const { packageName } = this.state;
8383
if (packageName !== prevState.packageName) {
84-
const { readMe, packageMeta } = await callDetailPage(packageName);
84+
const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial<StateInterface>;
8585
this.setState({
8686
readMe,
8787
packageMeta,
@@ -125,7 +125,7 @@ class VersionPage extends Component<PropsInterface, StateInterface> {
125125
});
126126

127127
try {
128-
const { readMe, packageMeta } = await callDetailPage(packageName);
128+
const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial<StateInterface>;
129129
this.setState({
130130
readMe,
131131
packageMeta,

src/utils/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string
2525
}
2626

2727
class API {
28-
public request(url: string, method = 'GET', options: any = {}): Promise<any> {
28+
public request<T>(url: string, method = 'GET', options?: RequestInit): Promise<T> {
2929
if (!window.VERDACCIO_API_URL) {
3030
throw new Error('VERDACCIO_API_URL is not defined!');
3131
}
3232

3333
const token = storage.getItem('token');
34-
if (token) {
35-
if (!options.headers) options.headers = {};
36-
37-
options.headers.authorization = `Bearer ${token}`;
34+
const headers = new Headers(options && options.headers);
35+
if (token && options && options.headers) {
36+
headers.set('Authorization', `Bearer ${token}`);
37+
options.headers = Object.assign(options.headers, headers);
3838
}
3939

4040
if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) {
4141
// @ts-ignore
4242
url = window.VERDACCIO_API_URL + url;
4343
}
4444

45-
return new Promise<any>((resolve, reject) => {
45+
return new Promise((resolve, reject) => {
4646
fetch(url, {
4747
method,
4848
credentials: 'same-origin',

src/utils/calls.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import API from './api';
22
import { PackageMetaInterface } from 'types/packageMeta';
33

44
export interface DetailPage {
5-
readMe: string;
6-
packageMeta: PackageMetaInterface;
5+
readMe: string | {};
6+
packageMeta: PackageMetaInterface | {};
77
}
88

99
export async function callDetailPage(packageName): Promise<DetailPage> {

0 commit comments

Comments
 (0)