mirror of
https://github.com/SomboChea/ui
synced 2024-11-24 06:54:27 +07:00
fix: improved typing (#174)
This commit is contained in:
parent
68b7171de4
commit
e0642a9d0d
@ -151,6 +151,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"type-check": "tsc --noEmit --pretty",
|
"type-check": "tsc --noEmit --pretty",
|
||||||
"type-check:watch": "npm run type-check -- --watch",
|
"type-check:watch": "npm run type-check -- --watch",
|
||||||
|
"type-check-strict:watch": "tsc --project ./tsconfig.strict.json --noEmit --pretty --watch",
|
||||||
"release": "standard-version -a",
|
"release": "standard-version -a",
|
||||||
"test:clean": "npx jest --clearCache",
|
"test:clean": "npx jest --clearCache",
|
||||||
"test:acceptance": "codeceptjs run --steps",
|
"test:acceptance": "codeceptjs run --steps",
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount, ReactWrapper } from 'enzyme';
|
||||||
|
|
||||||
import storage from '../utils/storage';
|
import storage from '../utils/storage';
|
||||||
import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__/token';
|
import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__/token';
|
||||||
|
|
||||||
import App from './App';
|
import App, { AppStateInterface } from './App';
|
||||||
|
|
||||||
jest.mock('../utils/storage', () => {
|
jest.mock('../utils/storage', () => {
|
||||||
class LocalStorageMock {
|
class LocalStorageMock {
|
||||||
private store: object;
|
private store: Record<string, string>;
|
||||||
public constructor() {
|
public constructor() {
|
||||||
this.store = {};
|
this.store = {};
|
||||||
}
|
}
|
||||||
public clear(): void {
|
public clear(): void {
|
||||||
this.store = {};
|
this.store = {};
|
||||||
}
|
}
|
||||||
public getItem(key): unknown {
|
public getItem(key: string): unknown {
|
||||||
return this.store[key] || null;
|
return this.store[key] || null;
|
||||||
}
|
}
|
||||||
public setItem(key, value): void {
|
public setItem(key: string, value: string): void {
|
||||||
this.store[key] = value.toString();
|
this.store[key] = value.toString();
|
||||||
}
|
}
|
||||||
public removeItem(key): void {
|
public removeItem(key: string): void {
|
||||||
delete this.store[key];
|
delete this.store[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ jest.mock('../utils/api', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('App', () => {
|
describe('App', () => {
|
||||||
let wrapper;
|
let wrapper: ReactWrapper<{}, AppStateInterface, App>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mount(<App />);
|
wrapper = mount(<App />);
|
||||||
|
@ -48,7 +48,7 @@ export default class App extends Component<{}, AppStateInterface> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
public componentDidUpdate(_, prevState): void {
|
public componentDidUpdate(_: AppStateInterface, prevState: AppStateInterface): void {
|
||||||
const { isUserLoggedIn } = this.state;
|
const { isUserLoggedIn } = this.state;
|
||||||
if (prevState.isUserLoggedIn !== isUserLoggedIn) {
|
if (prevState.isUserLoggedIn !== isUserLoggedIn) {
|
||||||
this.loadOnHandler();
|
this.loadOnHandler();
|
||||||
@ -99,7 +99,7 @@ export default class App extends Component<{}, AppStateInterface> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public setLoading = isLoading =>
|
public setLoading = (isLoading: boolean) =>
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoading,
|
isLoading,
|
||||||
});
|
});
|
||||||
@ -118,7 +118,7 @@ export default class App extends Component<{}, AppStateInterface> {
|
|||||||
* handles login
|
* handles login
|
||||||
* Required by: <Header />
|
* Required by: <Header />
|
||||||
*/
|
*/
|
||||||
public handleDoLogin = async (usernameValue, passwordValue) => {
|
public handleDoLogin = async (usernameValue: string, passwordValue: string) => {
|
||||||
const { username, token, error } = await makeLogin(usernameValue, passwordValue);
|
const { username, token, error } = await makeLogin(usernameValue, passwordValue);
|
||||||
|
|
||||||
if (username && token) {
|
if (username && token) {
|
||||||
@ -135,7 +135,7 @@ export default class App extends Component<{}, AppStateInterface> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public setLoggedUser = username => {
|
public setLoggedUser = (username: string) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
user: {
|
user: {
|
||||||
username,
|
username,
|
||||||
|
@ -6,17 +6,17 @@ export interface ErrorProps {
|
|||||||
|
|
||||||
export interface ErrorAppState {
|
export interface ErrorAppState {
|
||||||
hasError: boolean;
|
hasError: boolean;
|
||||||
error: any;
|
error: Error | null;
|
||||||
info: any;
|
info: object | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ErrorBoundary extends Component<ErrorProps, ErrorAppState> {
|
export default class ErrorBoundary extends Component<ErrorProps, ErrorAppState> {
|
||||||
constructor(props) {
|
constructor(props: ErrorProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { hasError: false, error: null, info: null };
|
this.state = { hasError: false, error: null, info: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidCatch(error, info) {
|
public componentDidCatch(error: Error, info: object) {
|
||||||
this.setState({ hasError: true, error, info });
|
this.setState({ hasError: true, error, info });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ export interface AvatarDeveloper {
|
|||||||
|
|
||||||
const AvatarTooltip: FC<AvatarDeveloper> = ({ name, packageName, version, avatar, email }) => {
|
const AvatarTooltip: FC<AvatarDeveloper> = ({ name, packageName, version, avatar, email }) => {
|
||||||
const avatarComponent = <Avatar aria-label={name} src={avatar} />;
|
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) {
|
if (!email || isEmail(email) === false) {
|
||||||
return avatarComponent;
|
return avatarComponent;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount, ReactWrapper } from 'enzyme';
|
||||||
|
|
||||||
import CopyToClipBoard from './CopyToClipBoard';
|
import CopyToClipBoard from './CopyToClipBoard';
|
||||||
import { CopyIcon } from './styles';
|
import { CopyIcon } from './styles';
|
||||||
|
|
||||||
describe('<CopyToClipBoard /> component', () => {
|
describe('<CopyToClipBoard /> component', () => {
|
||||||
let wrapper;
|
let wrapper: ReactWrapper;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mount(<CopyToClipBoard text={'copy text'} />);
|
wrapper = mount(<CopyToClipBoard text={'copy text'} />);
|
||||||
|
@ -12,7 +12,7 @@ interface Props {
|
|||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderText = (text, children): JSX.Element => {
|
const renderText = (text: string, children: React.ReactNode): JSX.Element => {
|
||||||
if (children) {
|
if (children) {
|
||||||
return <ClipBoardCopyText>{children}</ClipBoardCopyText>;
|
return <ClipBoardCopyText>{children}</ClipBoardCopyText>;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class Engine extends Component {
|
|||||||
return <Grid container={true}>{items}</Grid>;
|
return <Grid container={true}>{items}</Grid>;
|
||||||
};
|
};
|
||||||
|
|
||||||
private renderListItems = (heading, text) => {
|
private renderListItems = (heading: string, text: string) => {
|
||||||
return (
|
return (
|
||||||
<List subheader={<Heading variant={'subtitle1'}>{text.split('-').join(' ')}</Heading>}>
|
<List subheader={<Heading variant={'subtitle1'}>{text.split('-').join(' ')}</Heading>}>
|
||||||
<EngineListItem button={true}>
|
<EngineListItem button={true}>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount, ReactWrapper } from 'enzyme';
|
||||||
|
|
||||||
import Footer from './Footer';
|
import Footer from './Footer';
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ jest.mock('../../../package.json', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('<Footer /> component', () => {
|
describe('<Footer /> component', () => {
|
||||||
let wrapper;
|
let wrapper: ReactWrapper;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
window.VERDACCIO_VERSION = 'v.1.0.0';
|
window.VERDACCIO_VERSION = 'v.1.0.0';
|
||||||
wrapper = mount(<Footer />);
|
wrapper = mount(<Footer />);
|
||||||
|
@ -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 (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<div>
|
<div>
|
||||||
@ -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 (
|
return (
|
||||||
<div className={classes.loginErrorMsg} id={'client-snackbar'}>
|
<div className={classes.loginErrorMsg} id={'client-snackbar'}>
|
||||||
<ErrorIcon className={classes.loginIcon} />
|
<ErrorIcon className={classes.loginIcon} />
|
||||||
|
@ -8,7 +8,7 @@ import App from './App';
|
|||||||
|
|
||||||
const rootNode = document.getElementById('root');
|
const rootNode = document.getElementById('root');
|
||||||
|
|
||||||
const renderApp = (Component): void => {
|
const renderApp = (Component: React.ElementType): void => {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<AppContainer>
|
<AppContainer>
|
||||||
<Component />
|
<Component />
|
||||||
|
@ -19,7 +19,7 @@ export function getRouterPackageName(params): string {
|
|||||||
return packageName;
|
return packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillTitle(text): string {
|
function fillTitle(text: string): string {
|
||||||
return `Verdaccio - ${text}`;
|
return `Verdaccio - ${text}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { PackageMetaInterface } from 'types/packageMeta';
|
|||||||
|
|
||||||
import API from './api';
|
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');
|
return await API.request<string | {}>(`package/readme/${packageName}${packageVersion ? `?v=${packageVersion}` : ''}`, 'GET');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,11 +49,11 @@ export function formatRepository(repository: any): string | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDate(lastUpdate): string {
|
export function formatDate(lastUpdate: string | number): string {
|
||||||
return format(new Date(lastUpdate), TIMEFORMAT);
|
return format(new Date(lastUpdate), TIMEFORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDateDistance(lastUpdate): string {
|
export function formatDateDistance(lastUpdate: Date | string | number): string {
|
||||||
return distanceInWordsToNow(new Date(lastUpdate));
|
return distanceInWordsToNow(new Date(lastUpdate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ export function isURL(url: string): boolean {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isEmail(email): boolean {
|
export function isEmail(email: string): boolean {
|
||||||
return isEmailValidator(email || '');
|
return isEmailValidator(email || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
tsconfig.strict.json
Normal file
6
tsconfig.strict.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noImplicitAny": true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user