From 0d64fae05d364878697e6a4d59e731e65828af86 Mon Sep 17 00:00:00 2001 From: Eddy Meals Date: Fri, 29 Nov 2024 13:13:51 -0800 Subject: [PATCH] Fix typescript errors --- src/renderer/editor/ApiLink.tsx | 12 +++++++++++- src/renderer/editor/HighlightedCode.tsx | 16 +++++++++++++--- src/renderer/modals/ConfirmModal.tsx | 7 +++---- src/renderer/modals/Modal.tsx | 4 ++-- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/renderer/editor/ApiLink.tsx b/src/renderer/editor/ApiLink.tsx index 9573388..3013f0d 100644 --- a/src/renderer/editor/ApiLink.tsx +++ b/src/renderer/editor/ApiLink.tsx @@ -4,12 +4,13 @@ import './ApiLink.css'; * Links to a section of the student API documentation, opening the help window or just jumping to * the appropriate section if the window is already open. The single text node child of this * component is used as the link text. + * @param props * @param props.dest - the section of the docs to jump to. TODO: figure out format * @param props.code - whether to display the link text in a monospaced font. */ export default function ApiLink({ dest, - code = false, + code, children, }: { dest: string; @@ -24,3 +25,12 @@ export default function ApiLink({ ); } +/** + * Default props for ApiLink. + */ +ApiLink.defaultProps = { + /** + * By default, link text is displayed in the inherited font. + */ + code: false, +}; diff --git a/src/renderer/editor/HighlightedCode.tsx b/src/renderer/editor/HighlightedCode.tsx index 9a7ef41..928e707 100644 --- a/src/renderer/editor/HighlightedCode.tsx +++ b/src/renderer/editor/HighlightedCode.tsx @@ -7,15 +7,16 @@ import './HighlightedCode.css'; * valid children of this component is text containing the code to be displayed. Common indentation * is removed from each line of code before display. Only spaces are considered indentation; tabs, * half-width spaces, and nonbreaking spaces are treated as content. + * @param props * @param props.indent - number of spaces of indentation to prepend to each line, after common * indentation is removed. */ export default function HighlightedCode({ children, - indent = 0, + indent, }: { children: string; - indent: number?; + indent: number; }) { const lines = children.split('\n'); if (lines.length && !lines[0].trim()) { @@ -28,7 +29,7 @@ export default function HighlightedCode({ const minIndent = Math.min( ...lines .filter((line) => line.trim().length) - .map((line) => line.match(/^ */)[0].length), + .map((line) => line.match(/^ */)![0].length), ); const formatted = lines .map((line) => ' '.repeat(indent) + line.slice(minIndent)) @@ -45,3 +46,12 @@ export default function HighlightedCode({ /> ); } +/** + * Default props for HighlightedCode. + */ +HighlightedCode.defaultProps = { + /** + * No indentation is added to code lines after stripping common indentation by default. + */ + indent: 0, +}; diff --git a/src/renderer/modals/ConfirmModal.tsx b/src/renderer/modals/ConfirmModal.tsx index 50de41d..71dc581 100644 --- a/src/renderer/modals/ConfirmModal.tsx +++ b/src/renderer/modals/ConfirmModal.tsx @@ -16,14 +16,14 @@ export default function ConfirmModal({ onConfirm, isActive, modalTitle, - noAutoClose = false, + noAutoClose, children, }: { onClose: () => void; onConfirm: () => void; isActive: boolean; modalTitle: string; - noAutoClose?: boolean; + noAutoClose: boolean; children: ReactNode; }) { const handleConfirm = () => { @@ -46,8 +46,7 @@ export default function ConfirmModal({ ); } /** - * Default properties for ConfirmModal. Not sure why we need this if we have the default - * deconstruction parameter but the linter cries if we leave it out. + * Default properties for ConfirmModal. */ ConfirmModal.defaultProps = { /** diff --git a/src/renderer/modals/Modal.tsx b/src/renderer/modals/Modal.tsx index df52b46..ece7df8 100644 --- a/src/renderer/modals/Modal.tsx +++ b/src/renderer/modals/Modal.tsx @@ -14,13 +14,13 @@ export default function Modal({ isActive, modalTitle, children, - className = '', + className, }: { onClose: () => void; isActive: boolean; modalTitle: string; children: ReactNode; - className?: string; + className: string; }) { return (