diff --git a/jest/unit/components/__mocks__/api.ts b/jest/unit/components/__mocks__/api.ts index e4816c0..9f81368 100644 --- a/jest/unit/components/__mocks__/api.ts +++ b/jest/unit/components/__mocks__/api.ts @@ -39,8 +39,9 @@ const register = (url, method = 'get', options = {}) => { * Bind API methods */ class API { - request() { - return register.call(null, ...arguments); + public request() { + const rest = arguments; + return register.call(null, ...rest); } } diff --git a/jest/unit/components/store/logo.ts b/jest/unit/components/store/logo.ts index ac64387..3a07b37 100644 --- a/jest/unit/components/store/logo.ts +++ b/jest/unit/components/store/logo.ts @@ -2,6 +2,6 @@ * Mock response for logo api * @returns {promise} */ -export default function() { +export default function(): Promise { return Promise.resolve('http://localhost/-/static/logo.png'); } diff --git a/src/App/App.test.tsx b/src/App/App.test.tsx index 91d302d..f3ef717 100644 --- a/src/App/App.test.tsx +++ b/src/App/App.test.tsx @@ -7,7 +7,7 @@ import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__ jest.mock('../utils/storage', () => { class LocalStorageMock { - store: object; + private store: object; public constructor() { this.store = {}; } diff --git a/src/App/App.tsx b/src/App/App.tsx index b75ddc4..24e14b8 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -19,7 +19,7 @@ export const AppContext = React.createContext(null); export const AppContextProvider = AppContext.Provider; export const AppContextConsumer = AppContext.Consumer; -export default class App extends Component { +export default class App extends Component { public state = { error: {}, // @ts-ignore diff --git a/src/components/DetailContainer/DetailContainer.tsx b/src/components/DetailContainer/DetailContainer.tsx index b5945c1..e7e30fa 100644 --- a/src/components/DetailContainer/DetailContainer.tsx +++ b/src/components/DetailContainer/DetailContainer.tsx @@ -14,7 +14,7 @@ interface DetailContainerState { tabPosition: number; } -class DetailContainer extends Component { +class DetailContainer

extends Component { public state = { tabPosition: 0, }; @@ -29,7 +29,7 @@ class DetailContainer extends Component { ); } - private handleChange = (event: any, tabPosition: number) => { + private handleChange = (event: React.ChangeEvent<{}>, tabPosition: number) => { event.preventDefault(); this.setState({ tabPosition }); }; diff --git a/src/components/RegistryInfoDialog/RegistryInfoDialog.tsx b/src/components/RegistryInfoDialog/RegistryInfoDialog.tsx index f2c7741..494fc7f 100644 --- a/src/components/RegistryInfoDialog/RegistryInfoDialog.tsx +++ b/src/components/RegistryInfoDialog/RegistryInfoDialog.tsx @@ -8,7 +8,7 @@ import { Props } from './types'; const LABEL = 'CLOSE'; -const RegistryInfoDialog: React.FC = ({ open = false, children, onClose }): any => ( +const RegistryInfoDialog: React.FC = ({ open = false, children, onClose }) => (

{'Register Info'} {children} diff --git a/src/components/Search/Search.test.tsx b/src/components/Search/Search.test.tsx index 27eecdc..795d106 100644 --- a/src/components/Search/Search.test.tsx +++ b/src/components/Search/Search.test.tsx @@ -154,7 +154,7 @@ describe(' component test', () => { beforeEach(() => { jest.resetModules(); jest.doMock('lodash/debounce', () => { - return function debounceMock(fn, delay) { + return function debounceMock(fn) { return fn; }; }); diff --git a/src/pages/version/Version.tsx b/src/pages/version/Version.tsx index a1b4e58..56c7c2c 100644 --- a/src/pages/version/Version.tsx +++ b/src/pages/version/Version.tsx @@ -39,7 +39,7 @@ interface StateInterface { notFound: boolean; } -class VersionPage extends Component { +class VersionPage extends Component> { constructor(props) { super(props); @@ -81,7 +81,7 @@ class VersionPage extends Component { public async componentDidUpdate(nextProps, prevState: StateInterface): Promise { const { packageName } = this.state; if (packageName !== prevState.packageName) { - const { readMe, packageMeta } = await callDetailPage(packageName); + const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial; this.setState({ readMe, packageMeta, @@ -125,7 +125,7 @@ class VersionPage extends Component { }); try { - const { readMe, packageMeta } = await callDetailPage(packageName); + const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial; this.setState({ readMe, packageMeta, diff --git a/src/utils/api.ts b/src/utils/api.ts index be94201..4713fc5 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -25,16 +25,16 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string } class API { - public request(url: string, method = 'GET', options: any = {}): Promise { + public request(url: string, method = 'GET', options?: RequestInit): Promise { if (!window.VERDACCIO_API_URL) { throw new Error('VERDACCIO_API_URL is not defined!'); } const token = storage.getItem('token'); - if (token) { - if (!options.headers) options.headers = {}; - - options.headers.authorization = `Bearer ${token}`; + const headers = new Headers(options && options.headers); + if (token && options && options.headers) { + headers.set('Authorization', `Bearer ${token}`); + options.headers = Object.assign(options.headers, headers); } if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) { @@ -42,7 +42,7 @@ class API { url = window.VERDACCIO_API_URL + url; } - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { fetch(url, { method, credentials: 'same-origin', diff --git a/src/utils/calls.ts b/src/utils/calls.ts index f44a36d..168fdde 100644 --- a/src/utils/calls.ts +++ b/src/utils/calls.ts @@ -2,8 +2,8 @@ import API from './api'; import { PackageMetaInterface } from 'types/packageMeta'; export interface DetailPage { - readMe: string; - packageMeta: PackageMetaInterface; + readMe: string | {}; + packageMeta: PackageMetaInterface | {}; } export async function callDetailPage(packageName): Promise { diff --git a/src/utils/file-size.ts b/src/utils/file-size.ts index c79ed35..28f20ea 100644 --- a/src/utils/file-size.ts +++ b/src/utils/file-size.ts @@ -1,4 +1,4 @@ -/* tslint:disable */ +/* @ts-ignore */ export default function fileSizeSI(a?: any, b?: any, c?: any, d?: any, e?: any) { return ((b = Math), (c = b.log), (d = 1e3), (e = (c(a) / c(d)) | 0), a / b.pow(d, e)).toFixed(2) + ' ' + (e ? 'kMGTPEZY'[--e] + 'B' : 'Bytes'); }