From 65bbfcf3daef5ac6cc31517144aefa8f51d7461a Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Sun, 4 Feb 2024 11:40:53 -0700 Subject: [PATCH] Lots of typescript improvements. --- @types/global.d.ts | 8 ++ src/components/common/BinaryDownload.tsx | 3 +- .../common/CompletedFilesCounter.tsx | 4 +- src/components/common/Diff/Diff.tsx | 1 + src/components/common/Diff/DiffComment.tsx | 9 ++- src/components/common/Diff/DiffHeader.tsx | 48 +++++++++--- src/components/common/Diff/DiffSection.tsx | 21 ++++-- .../common/Diff/DiffViewStyleOptions.tsx | 6 +- src/components/common/DiffViewer.tsx | 53 +++++++++---- src/components/common/DownloadFileButton.tsx | 16 +++- src/components/common/Select.tsx | 2 +- src/components/common/Settings.tsx | 19 ++++- .../common/TroubleshootingGuidesButton.tsx | 4 +- src/components/common/UpgradeButton.tsx | 11 ++- src/components/common/UpgradeSupportAlert.tsx | 1 - .../common/UsefulContentSection.tsx | 2 +- src/components/common/VersionSelector.tsx | 74 +++++++++++++++---- src/components/common/ViewFileButton.tsx | 10 ++- src/components/pages/Home.tsx | 34 ++++++--- src/hooks/fetch-diff.ts | 4 +- src/hooks/fetch-release-versions.ts | 12 ++- src/releases/react-native/0.68.tsx | 25 ++++--- src/utils/test-utils.ts | 6 +- src/utils/update-url.ts | 8 +- tsconfig.json | 12 ++- yarn.lock | 27 +++++-- 26 files changed, 308 insertions(+), 112 deletions(-) create mode 100644 @types/global.d.ts diff --git a/@types/global.d.ts b/@types/global.d.ts new file mode 100644 index 00000000..054694fb --- /dev/null +++ b/@types/global.d.ts @@ -0,0 +1,8 @@ +interface Window {} + +interface Process { + env: { + PUBLIC_URL: string + NODE_ENV: 'development' | 'production' + } +} diff --git a/src/components/common/BinaryDownload.tsx b/src/components/common/BinaryDownload.tsx index 9754b534..8b97f76b 100644 --- a/src/components/common/BinaryDownload.tsx +++ b/src/components/common/BinaryDownload.tsx @@ -5,6 +5,7 @@ import styled from '@emotion/styled' import DownloadFileButton from './DownloadFileButton' import { removeAppPathPrefix } from '../../utils' import type { Theme } from '../../theme' +import type { File } from 'gitdiff-parser' const Container = styled.div` padding-right: 10px; @@ -41,7 +42,7 @@ const Popover = styled(({ className, ...props }: PopoverProps) => ( ` interface BinaryListProps { - binaryFiles: { newPath: string }[] + binaryFiles: File[] toVersion: string appName: string packageName: string diff --git a/src/components/common/CompletedFilesCounter.tsx b/src/components/common/CompletedFilesCounter.tsx index 13e249f6..ed40affd 100644 --- a/src/components/common/CompletedFilesCounter.tsx +++ b/src/components/common/CompletedFilesCounter.tsx @@ -32,8 +32,8 @@ interface CompletedFilesCounterProps completed: number total: number popoverContent: string - popoverCursorType: string - theme: Theme + popoverCursorType: React.CSSProperties['cursor'] + theme?: Theme } const CompletedFilesCounter = styled( diff --git a/src/components/common/Diff/Diff.tsx b/src/components/common/Diff/Diff.tsx index c9ee2f94..7eb1fe44 100644 --- a/src/components/common/Diff/Diff.tsx +++ b/src/components/common/Diff/Diff.tsx @@ -331,6 +331,7 @@ const Diff = ({ , ])} diff --git a/src/components/common/Diff/DiffComment.tsx b/src/components/common/Diff/DiffComment.tsx index ce3496d8..b0d46154 100644 --- a/src/components/common/Diff/DiffComment.tsx +++ b/src/components/common/Diff/DiffComment.tsx @@ -118,7 +118,12 @@ const getLineNumberWithType = ({ }: { lineChangeType: LineChangeT lineNumber: number -}) => `${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}` +}) => + `${ + LINE_CHANGE_TYPES[ + lineChangeType.toUpperCase() as keyof typeof LINE_CHANGE_TYPES + ] + }${lineNumber}` const getComments = ({ packageName, @@ -178,7 +183,7 @@ const DiffComment = ({ content: any lineChangeType: LineChangeT }) => { - const [isCommentOpen, setIsCommentOpen] = useState(true) + const [isCommentOpen, setIsCommentOpen] = useState(true) return ( { +const FileName = ({ + oldPath, + newPath, + type, +}: { + oldPath: string + newPath: string + type: LineChangeT +}) => { if (type === 'delete') { return {oldPath} } @@ -63,7 +73,7 @@ const FileName = ({ oldPath, newPath, type, appName }) => { return {newPath} } -function generatePathId(oldPath, newPath) { +function generatePathId(oldPath: string, newPath: string) { const isMoved = oldPath !== newPath if (newPath === '/dev/null') { newPath = 'deleted' @@ -72,7 +82,12 @@ function generatePathId(oldPath, newPath) { return encodeURIComponent(path.replace(/[/\\]/g, '-')) } -const FileStatus = ({ type, ...props }) => { +const FileStatus = ({ + type, + ...props +}: { + type: DiffType +} & TagProps) => { const colors = { add: 'blue', modify: 'green', @@ -88,13 +103,16 @@ const FileStatus = ({ type, ...props }) => { } return ( - - {labels[type]} + + {labels[type as keyof typeof labels]} ) } -const BinaryBadge = ({ open, ...props }) => +interface BinaryBadgeProps extends TagProps { + open: boolean +} +const BinaryBadge = ({ open, ...props }: BinaryBadgeProps) => open ? ( BINARY @@ -206,7 +224,7 @@ const CopyAnchorLinksToClipboardButton = styled( const onCopyContent = () => setContent(copyAnchorLinks.copied) const url = React.useMemo(() => { - const url = new URL(window.location) + const url = new URL(window.location.toString()) url.hash = id url.searchParams.set('from', fromVersion) url.searchParams.set('to', toVersion) @@ -244,8 +262,15 @@ const CollapseClickableArea = styled.div` } ` -const CollapseDiffButton = styled(({ open, isDiffCollapsed, ...props }) => - open ?