refactor: mollify TypeScript

This commit is contained in:
Oliver Eyton-Williams
2021-11-24 15:09:45 +01:00
committed by Mrugesh Mohapatra
parent 7d0760c98f
commit 01b354f0d1
9 changed files with 46 additions and 32 deletions

View File

@ -116,14 +116,10 @@ const ShowProjectLinks = (props: ShowProjectLinksProps): JSX.Element => {
{ title: 'Data Visualization' }, { title: 'Data Visualization' },
{ title: 'Back End Development and APIs' }, { title: 'Back End Development and APIs' },
{ title: 'Legacy Information Security and Quality Assurance' } { title: 'Legacy Information Security and Quality Assurance' }
]; ] as const;
return legacyCerts.map((cert, ind) => { return legacyCerts.map((cert, ind) => {
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ const mapToUse = (projectMap[cert.title] ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ legacyProjectMap[cert.title]) as { certSlug: string }[];
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// @ts-expect-error Error expected until projectMap is typed
const mapToUse = projectMap[cert.title] || legacyProjectMap[cert.title];
const { certSlug } = first(mapToUse) as { certSlug: string }; const { certSlug } = first(mapToUse) as { certSlug: string };
const certLocation = `/certification/${username}/${certSlug}`; const certLocation = `/certification/${username}/${certSlug}`;
return ( return (
@ -141,17 +137,19 @@ const ShowProjectLinks = (props: ShowProjectLinksProps): JSX.Element => {
}); });
} }
// @ts-expect-error Error expected until projectMap is typed // @ts-expect-error Error expected until projectMap is typed
return (projectMap[certName] || legacyProjectMap[certName]).map( const project = (projectMap[certName] || legacyProjectMap[certName]) as {
// @ts-expect-error Error expected until projectMap is typed link: string;
({ link, title, id }) => ( title: string;
<li key={id}> id: string;
<Link className='project-link' to={link}> }[];
{t(`certification.project.title.${title as string}`, title)} return project.map(({ link, title, id }) => (
</Link> <li key={id}>
: {getProjectSolution(id, title)} <Link className='project-link' to={link}>
</li> {t(`certification.project.title.${title}`, title)}
) </Link>
); : {getProjectSolution(id, title)}
</li>
));
/* eslint-enable @typescript-eslint/no-unsafe-assignment */ /* eslint-enable @typescript-eslint/no-unsafe-assignment */
/* eslint-enable @typescript-eslint/no-unsafe-call */ /* eslint-enable @typescript-eslint/no-unsafe-call */
/* eslint-enable @typescript-eslint/no-unsafe-return */ /* eslint-enable @typescript-eslint/no-unsafe-return */

View File

@ -101,7 +101,12 @@ function FormFields(props: FormFieldsProps): JSX.Element {
type={type} type={type}
value={value as string} value={value as string}
/> />
{nullOrWarning(value, !pristine && error, isURL, name)} {nullOrWarning(
value as string,
!pristine && error,
isURL,
name
)}
</FormGroup> </FormGroup>
</Col> </Col>
); );

View File

@ -17,6 +17,7 @@ import './heatmap.css';
// @ts-ignore // @ts-ignore
import envData from '../../../../../config/env.json'; import envData from '../../../../../config/env.json';
import { langCodes } from '../../../../../config/i18n/all-langs'; import { langCodes } from '../../../../../config/i18n/all-langs';
import { User } from '../../../redux/prop-types';
import FullWidthRow from '../../helpers/full-width-row'; import FullWidthRow from '../../helpers/full-width-row';
import Spacer from '../../helpers/spacer'; import Spacer from '../../helpers/spacer';
@ -29,8 +30,7 @@ const { clientLocale } = envData;
const localeCode = langCodes[clientLocale]; const localeCode = langCodes[clientLocale];
interface HeatMapProps { interface HeatMapProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any calendar: User['calendar'];
calendar: any;
} }
interface PageData { interface PageData {
@ -186,7 +186,6 @@ class HeatMapInner extends Component<HeatMapInnerProps, HeatMapInnerState> {
const HeatMap = (props: HeatMapProps): JSX.Element => { const HeatMap = (props: HeatMapProps): JSX.Element => {
const { t } = useTranslation(); const { t } = useTranslation();
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { calendar } = props; const { calendar } = props;
/** /**
@ -195,8 +194,9 @@ const HeatMap = (props: HeatMapProps): JSX.Element => {
*/ */
// create array of timestamps and turn into milliseconds // create array of timestamps and turn into milliseconds
// eslint-disable-next-line @typescript-eslint/no-explicit-any const timestamps = Object.keys(calendar).map(
const timestamps = Object.keys(calendar).map((stamp: any) => stamp * 1000); stamp => Number.parseInt(stamp, 10) * 1000
);
const startOfTimestamps = startOfDay(new Date(timestamps[0])); const startOfTimestamps = startOfDay(new Date(timestamps[0]));
let endOfCalendar = startOfDay(Date.now()); let endOfCalendar = startOfDay(Date.now());
let startOfCalendar; let startOfCalendar;

View File

@ -57,6 +57,7 @@ const CustomHits = connectHits(
]; ];
const allHits = hits.slice(0, 8).concat(footer); const allHits = hits.slice(0, 8).concat(footer);
useEffect(() => { useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
handleHits(allHits); handleHits(allHits);
}); });

View File

@ -220,7 +220,7 @@ export type CertTest = {
}; };
export type User = { export type User = {
calendar: unknown; calendar: Record<string, number>;
about: string; about: string;
acceptedPrivacyTerms: boolean; acceptedPrivacyTerms: boolean;
completedChallenges: CompletedChallenge[]; completedChallenges: CompletedChallenge[];

View File

@ -64,7 +64,7 @@ const DesktopLayout = (props: DesktopLayoutProps): JSX.Element => {
const getChallengeFile = () => { const getChallengeFile = () => {
const { challengeFiles } = props; const { challengeFiles } = props;
return first(sortChallengeFiles(challengeFiles)) as ChallengeFile | null; return first(sortChallengeFiles(challengeFiles) as ChallengeFile[]);
}; };
const { const {

View File

@ -13,7 +13,7 @@ interface CompletionModalBodyProps {
interface CompletionModalBodyState { interface CompletionModalBodyState {
// This type was driving me nuts - seems like `NodeJS.Timeout | null;` should work // This type was driving me nuts - seems like `NodeJS.Timeout | null;` should work
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
progressInterval: any; progressInterval: number | null;
shownPercent: number; shownPercent: number;
} }
@ -45,7 +45,7 @@ export class CompletionModalBody extends PureComponent<
const amountPerInterval = completedPercent / intervalsToFinish; const amountPerInterval = completedPercent / intervalsToFinish;
let percent = 0; let percent = 0;
const myInterval = setInterval(() => { const myInterval = window.setInterval(() => {
percent += amountPerInterval; percent += amountPerInterval;
if (percent > completedPercent) percent = completedPercent; if (percent > completedPercent) percent = completedPercent;
@ -65,7 +65,8 @@ export class CompletionModalBody extends PureComponent<
} }
componentWillUnmount(): void { componentWillUnmount(): void {
clearInterval(this.state.progressInterval); if (this.state.progressInterval !== null)
clearInterval(this.state.progressInterval);
} }
render(): JSX.Element { render(): JSX.Element {

View File

@ -35,6 +35,14 @@ type Meta = {
challengeOrder: string[][]; challengeOrder: string[][];
}; };
interface CreateProjectArgs {
superBlock: SuperBlocks;
block: string;
helpCategory: string;
order: number;
title?: string;
}
async function createProject( async function createProject(
superBlock: SuperBlocks, superBlock: SuperBlocks,
block: string, block: string,
@ -264,8 +272,9 @@ prompt([
} }
} }
]) ])
.then(({ superBlock, block, title, helpCategory, order }) => .then(
createProject(superBlock, block, helpCategory, order, title) ({ superBlock, block, title, helpCategory, order }: CreateProjectArgs) =>
createProject(superBlock, block, helpCategory, order, title)
) )
.then(() => .then(() =>
console.log( console.log(

View File

@ -59,7 +59,7 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
searchKeys, searchKeys,
donationKeys donationKeys
); );
const receivedvariables = Object.keys(env); const receivedvariables = Object.keys(env as Record<string, unknown>);
expectedVariables.sort(); expectedVariables.sort();
receivedvariables.sort(); receivedvariables.sort();
if (expectedVariables.length !== receivedvariables.length) { if (expectedVariables.length !== receivedvariables.length) {