diff --git a/package.json b/package.json index 045d9eba..d4c62b1e 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,6 @@ "postinstall-postinstall": "^2.1.0", "prismjs": "^1.30.0", "prismjs-bibtex": "^2.1.0", - "prop-types": "^15.8.1", "react": "^19.3.1", "react-dom": "^19.3.1", "react-dropzone": "^20.2.0", diff --git a/scripts/typecheck-baseline.txt b/scripts/typecheck-baseline.txt index 5f0f0037..e69de29b 100644 --- a/scripts/typecheck-baseline.txt +++ b/scripts/typecheck-baseline.txt @@ -1,4 +0,0 @@ -src/app/App.js(466,12): error TS2739: Type '{ error: ErrorObject; onClose: () => void; }' is missing the following properties from type '{ error: any; onClose: any; needReload: any; title: any; }': needReload, title -src/app/App.js(512,10): error TS2741: Property 'needReload' is missing in type '{ error: unknown; title: string; onClose: () => void; }' but required in type '{ error: any; onClose: any; needReload: any; title: any; }'. -src/app/App.test.js(5,1): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. -src/app/App.test.js(13,3): error TS2304: Cannot find name 'expect'. diff --git a/src/app/AlignmentCard.tsx b/src/app/AlignmentCard.tsx index 166d3bb9..1dbb18bd 100644 --- a/src/app/AlignmentCard.tsx +++ b/src/app/AlignmentCard.tsx @@ -62,7 +62,8 @@ interface CardAlignment { interface CardFinalAlignment { dataType?: string; numSequences: number; - numSequencesParsed: number; + // Absent on the store FinalAlignment; its parsingComplete is always true. + numSequencesParsed?: number; length: number; numAlignments: number; filename: string; diff --git a/src/app/App.test.js b/src/app/App.test.js index 431e6449..380f08bf 100644 --- a/src/app/App.test.js +++ b/src/app/App.test.js @@ -1,3 +1,4 @@ +// @ts-nocheck — Jest globals. checkJs has no test runner types. import React, { act } from 'react'; import { createRoot } from 'react-dom/client'; import Page from './index'; diff --git a/src/app/App.js b/src/app/App.tsx similarity index 97% rename from src/app/App.js rename to src/app/App.tsx index 293e452f..ef2bae47 100644 --- a/src/app/App.js +++ b/src/app/App.tsx @@ -34,7 +34,7 @@ import ErrorBoundary from './components/ErrorBoundary'; import ErrorDialog from './components/ErrorDialog'; import ModifiedDialog from './components/ModifiedDialog'; -const VerticalHeading = styled( Typography )( ( { theme } ) => ( { +const VerticalHeading = styled( Typography )( () => ( { writingMode: 'vertical-rl', textOrientation: 'upright', padding: '10px 5px', @@ -43,7 +43,20 @@ const VerticalHeading = styled( Typography )( ( { theme } ) => ( { borderRight: '1px solid #ccc', } ) ); -const App = () => { +interface SnackRun { + converted: boolean; + convertedAlignmentFrom: string | null; + modified: boolean; + showModifiedSnack: boolean; + clearShowModified: () => void; +} + +interface SnackStore { + showAppSnack: boolean; + clearAppSnack: () => void; +} + +const App = (): React.JSX.Element => { const TabItems = store.runs.map( ( run ) => ( { /> ) ); - function fileModifiedSnack( run ) { + function fileModifiedSnack( run: SnackRun ): React.JSX.Element { let message = 'Something happened'; if ( run.converted ) { message = `Converted your ${run.convertedAlignmentFrom} alignment into fasta!`; @@ -107,7 +120,7 @@ const App = () => { ); } - function appSnack( store ) { + function appSnack( store: SnackStore ): React.JSX.Element { const message = 'Command copied'; return ( void; addPartitionFiles: ( files: DroppedFile[] ) => void; addTreeFiles: ( type: string, files: DroppedFile[] ) => void; addAstralFiles: ( file: DroppedFile ) => void; inputIsAlignment: boolean; - alignments: { path: string }[]; + alignments: ( AlignmentCardProps['alignment'] & { path: string } )[]; inputIsTree: boolean; - astralTree: unknown; + astralTree: AstralTreeCardProps['astralTree']; canLoadAlignment: boolean; haveAlignments: boolean; canLoadPartitionFile: boolean; @@ -42,8 +47,8 @@ interface InputRun { loadBackboneConstraintFile: () => void; multifurcatingConstraint: InputTree; loadMultifurcatingConstraintFile: () => void; - finalAlignment: unknown; -} + finalAlignment: FinalAlignmentCardProps['alignment']; +}; export interface InputProps { run: InputRun; diff --git a/src/app/TreeCard.tsx b/src/app/TreeCard.tsx index a111c025..95e6e68b 100644 --- a/src/app/TreeCard.tsx +++ b/src/app/TreeCard.tsx @@ -14,7 +14,8 @@ import type { SxProps, Theme } from '@mui/material/styles'; interface CardTree { name: string; - loading: boolean; + // The store Tree has no loading flag, so this always reads undefined. + loading?: boolean; openFile: () => void; openFolder: () => void; remove: () => void; diff --git a/src/app/components/ErrorDialog.js b/src/app/components/ErrorDialog.tsx similarity index 88% rename from src/app/components/ErrorDialog.js rename to src/app/components/ErrorDialog.tsx index 53034be8..2c817c06 100644 --- a/src/app/components/ErrorDialog.js +++ b/src/app/components/ErrorDialog.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import PropTypes from 'prop-types'; import { Box } from '@mui/material'; import Dialog from '@mui/material/Dialog'; import DialogTitle from '@mui/material/DialogTitle'; @@ -17,11 +16,27 @@ import { getMailtoLinkToReportError } from '../report'; import { reportIssueToGitHub } from '../githubIssue'; const handleReload = () => { - const { rendererBridge } = /** @type {any} */ ( window ); - return rendererBridge.reload(); + return window.rendererBridge.reload(); }; -export default function ErrorDialog( { error, onClose, needReload, title } ) { +type DialogError = Error & { isUserFix?: boolean }; + +export interface ErrorDialogProps { + // Store errors are caught values (unknown) or serialized bridge errors. + error?: unknown; + onClose: () => void; + needReload?: boolean; + title?: string | null; +} + +export default function ErrorDialog( { + error: caught, + onClose, + needReload, + title, +}: ErrorDialogProps ): React.JSX.Element | null { + // The dialog reads name, message and isUserFix as the untyped component did. + const error = caught as DialogError | null | undefined; const [reported, setReported] = React.useState( false ); const mailtoContent = React.useMemo( () => ( error @@ -171,10 +186,3 @@ export default function ErrorDialog( { error, onClose, needReload, title } ) { return returnDialog; } - -ErrorDialog.propTypes = { - error: PropTypes.object, - onClose: PropTypes.func.isRequired, - needReload: PropTypes.bool, - title: PropTypes.string, -}; diff --git a/src/app/index.js b/src/app/index.tsx similarity index 95% rename from src/app/index.js rename to src/app/index.tsx index 836d07db..efbd31d3 100644 --- a/src/app/index.js +++ b/src/app/index.tsx @@ -16,7 +16,7 @@ if ( process.env.NODE_ENV !== 'development' ) { } ); } -const Index = () => { +const Index = (): React.JSX.Element => { const { light, dark } = theme; const muiTheme = store.config.isDarkMode ? dark diff --git a/src/pageNodeImports.test.js b/src/pageNodeImports.test.js index 37a3aeb0..c3930c98 100644 --- a/src/pageNodeImports.test.js +++ b/src/pageNodeImports.test.js @@ -44,6 +44,6 @@ it( 'the page can still import the user-fix error type and the alignment typeche expect( alignment ).toMatch( /from ['"]\.\.\/\.\.\/common\/typecheckAlignment['"]/ ); expect( alignment ).toMatch( /from ['"]\.\.\/\.\.\/common\/errors['"]/ ); expect( run ).toMatch( /from ['"]\.\.\/\.\.\/common\/errors['"]/ ); - expect( fs.readFileSync( path.join( __dirname, 'app', 'index.js' ), 'utf8' ) ) + expect( fs.readFileSync( path.join( __dirname, 'app', 'index.tsx' ), 'utf8' ) ) .not.toMatch( /from ['"]\.\.\/common\/utils['"]/ ); } );