Skip to content

Commit 65bbfcf

Browse files
committed
Lots of typescript improvements.
1 parent 2551049 commit 65bbfcf

26 files changed

+308
-112
lines changed

@types/global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface Window {}
2+
3+
interface Process {
4+
env: {
5+
PUBLIC_URL: string
6+
NODE_ENV: 'development' | 'production'
7+
}
8+
}

src/components/common/BinaryDownload.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styled from '@emotion/styled'
55
import DownloadFileButton from './DownloadFileButton'
66
import { removeAppPathPrefix } from '../../utils'
77
import type { Theme } from '../../theme'
8+
import type { File } from 'gitdiff-parser'
89

910
const Container = styled.div`
1011
padding-right: 10px;
@@ -41,7 +42,7 @@ const Popover = styled(({ className, ...props }: PopoverProps) => (
4142
`
4243

4344
interface BinaryListProps {
44-
binaryFiles: { newPath: string }[]
45+
binaryFiles: File[]
4546
toVersion: string
4647
appName: string
4748
packageName: string

src/components/common/CompletedFilesCounter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ interface CompletedFilesCounterProps
3232
completed: number
3333
total: number
3434
popoverContent: string
35-
popoverCursorType: string
36-
theme: Theme
35+
popoverCursorType: React.CSSProperties['cursor']
36+
theme?: Theme
3737
}
3838

3939
const CompletedFilesCounter = styled(

src/components/common/Diff/Diff.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ const Diff = ({
331331
<Hunk
332332
key={hunk.content}
333333
hunk={hunk}
334+
// @ts-ignore-next-line
334335
gutterEvents={{ onClick: onToggleChangeSelection }}
335336
/>,
336337
])}

src/components/common/Diff/DiffComment.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ const getLineNumberWithType = ({
118118
}: {
119119
lineChangeType: LineChangeT
120120
lineNumber: number
121-
}) => `${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}`
121+
}) =>
122+
`${
123+
LINE_CHANGE_TYPES[
124+
lineChangeType.toUpperCase() as keyof typeof LINE_CHANGE_TYPES
125+
]
126+
}${lineNumber}`
122127

123128
const getComments = ({
124129
packageName,
@@ -178,7 +183,7 @@ const DiffComment = ({
178183
content: any
179184
lineChangeType: LineChangeT
180185
}) => {
181-
const [isCommentOpen, setIsCommentOpen] = useState(true)
186+
const [isCommentOpen, setIsCommentOpen] = useState<boolean>(true)
182187

183188
return (
184189
<Container

src/components/common/Diff/DiffHeader.tsx

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import styled from '@emotion/styled'
33
import { Tag, Button, Popover } from 'antd'
4-
import type { ButtonProps } from 'antd'
4+
import type { ButtonProps, TagProps } from 'antd'
55
import {
66
CheckOutlined,
77
DownOutlined,
@@ -17,6 +17,8 @@ import DownloadFileButton from '../DownloadFileButton'
1717
import ViewFileButton from '../ViewFileButton'
1818
import CopyFileButton from '../CopyFileButton'
1919
import type { Theme } from '../../../theme'
20+
import type { LineChangeT } from '../../../releases/types'
21+
import type { DiffType } from 'react-diff-view'
2022

2123
export const testIDs = {
2224
collapseClickableArea: 'collapseClickableArea',
@@ -47,7 +49,15 @@ const FileRenameArrow = styled(RightOutlined)({
4749
color: '#f78206',
4850
})
4951

50-
const FileName = ({ oldPath, newPath, type, appName }) => {
52+
const FileName = ({
53+
oldPath,
54+
newPath,
55+
type,
56+
}: {
57+
oldPath: string
58+
newPath: string
59+
type: LineChangeT
60+
}) => {
5161
if (type === 'delete') {
5262
return <span>{oldPath}</span>
5363
}
@@ -63,7 +73,7 @@ const FileName = ({ oldPath, newPath, type, appName }) => {
6373
return <span>{newPath}</span>
6474
}
6575

66-
function generatePathId(oldPath, newPath) {
76+
function generatePathId(oldPath: string, newPath: string) {
6777
const isMoved = oldPath !== newPath
6878
if (newPath === '/dev/null') {
6979
newPath = 'deleted'
@@ -72,7 +82,12 @@ function generatePathId(oldPath, newPath) {
7282
return encodeURIComponent(path.replace(/[/\\]/g, '-'))
7383
}
7484

75-
const FileStatus = ({ type, ...props }) => {
85+
const FileStatus = ({
86+
type,
87+
...props
88+
}: {
89+
type: DiffType
90+
} & TagProps) => {
7691
const colors = {
7792
add: 'blue',
7893
modify: 'green',
@@ -88,13 +103,16 @@ const FileStatus = ({ type, ...props }) => {
88103
}
89104

90105
return (
91-
<Tag {...props} color={colors[type]}>
92-
{labels[type]}
106+
<Tag {...props} color={colors[type as keyof typeof colors]}>
107+
{labels[type as keyof typeof labels]}
93108
</Tag>
94109
)
95110
}
96111

97-
const BinaryBadge = ({ open, ...props }) =>
112+
interface BinaryBadgeProps extends TagProps {
113+
open: boolean
114+
}
115+
const BinaryBadge = ({ open, ...props }: BinaryBadgeProps) =>
98116
open ? (
99117
<Tag {...props} color="cyan">
100118
BINARY
@@ -206,7 +224,7 @@ const CopyAnchorLinksToClipboardButton = styled(
206224
const onCopyContent = () => setContent(copyAnchorLinks.copied)
207225

208226
const url = React.useMemo(() => {
209-
const url = new URL(window.location)
227+
const url = new URL(window.location.toString())
210228
url.hash = id
211229
url.searchParams.set('from', fromVersion)
212230
url.searchParams.set('to', toVersion)
@@ -244,8 +262,15 @@ const CollapseClickableArea = styled.div`
244262
}
245263
`
246264

247-
const CollapseDiffButton = styled(({ open, isDiffCollapsed, ...props }) =>
248-
open ? <Button {...props} type="link" icon={<DownOutlined />} /> : null
265+
interface CollapseDiffButtonProps extends ButtonProps {
266+
open: boolean
267+
isDiffCollapsed: boolean
268+
theme?: Theme
269+
}
270+
271+
const CollapseDiffButton = styled(
272+
({ open, isDiffCollapsed, ...props }: CollapseDiffButtonProps) =>
273+
open ? <Button {...props} type="link" icon={<DownOutlined />} /> : null
249274
)`
250275
color: ${({ theme }) => theme.text};
251276
margin-right: 2px;
@@ -266,7 +291,7 @@ interface DiffHeaderProps extends WrapperProps {
266291
newPath: string
267292
fromVersion: string
268293
toVersion: string
269-
type: string
294+
type: DiffType
270295
diffKey: string
271296
hasDiff: boolean
272297
isDiffCollapsed: boolean
@@ -330,7 +355,6 @@ const DiffHeader = ({
330355
oldPath={sanitizedFilePaths.oldPath}
331356
newPath={sanitizedFilePaths.newPath}
332357
type={type}
333-
appName={appName}
334358
/>{' '}
335359
<FileStatus type={type} />
336360
<BinaryBadge open={!hasDiff} />

src/components/common/Diff/DiffSection.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Typography } from 'antd'
33
import styled from '@emotion/styled'
44
import semver from 'semver'
55
import Diff from './Diff'
6+
import type { File } from 'gitdiff-parser'
7+
import type { ViewType } from 'react-diff-view'
68

79
export const testIDs = {
810
diffSection: 'diffSection',
@@ -15,19 +17,19 @@ const Title = styled(Typography.Title)`
1517
interface DiffSectionProps {
1618
packageName: string
1719
diff: any
18-
getDiffKey: (diffFile: any) => string
19-
title: string
20+
getDiffKey: (file: File) => string
21+
title?: string
2022
completedDiffs: string[]
2123
isDoneSection: boolean
2224
fromVersion: string
2325
toVersion: string
2426
handleCompleteDiff: (diffKey: string) => void
2527
selectedChanges: string[]
26-
onToggleChangeSelection: (diffKey: string, isSelected: boolean) => void
27-
diffViewStyle: string
28+
onToggleChangeSelection: (diffKey: string) => void
29+
diffViewStyle: ViewType
2830
appName: string
2931
appPackage: string
30-
doneTitleRef: React.RefObject<HTMLHeadingElement>
32+
doneTitleRef?: React.RefObject<HTMLHeadingElement>
3133
}
3234

3335
const DiffSection = ({
@@ -47,7 +49,9 @@ const DiffSection = ({
4749
appPackage,
4850
doneTitleRef,
4951
}: DiffSectionProps) => {
50-
const [areAllCollapsed, setAllCollapsed] = useState(undefined)
52+
const [areAllCollapsed, setAllCollapsed] = useState<boolean | undefined>(
53+
undefined
54+
)
5155

5256
const getIsUpgradingFrom61To62 = useCallback(() => {
5357
const isUpgradingFrom61 = semver.satisfies(
@@ -70,7 +74,7 @@ const DiffSection = ({
7074
</Title>
7175
)}
7276

73-
{diff.map((diffFile) => {
77+
{diff.map((diffFile: File) => {
7478
const diffKey = getDiffKey(diffFile)
7579
const isDiffCompleted = completedDiffs.includes(diffKey)
7680

@@ -92,10 +96,11 @@ const DiffSection = ({
9296

9397
return (
9498
<Diff
95-
key={`${diffFile.oldRevision}${diffFile.newRevision}`}
99+
key={diffKey}
96100
{...diffFile}
97101
packageName={packageName}
98102
// otakustay/react-diff-view#49
103+
// @ts-ignore-next-line
99104
type={diffFile.type === 'new' ? 'add' : diffFile.type}
100105
diffKey={diffKey}
101106
diffViewStyle={diffViewStyle}

src/components/common/Diff/DiffViewStyleOptions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import React from 'react'
22
import styled from '@emotion/styled'
33
import { Radio } from 'antd'
44
import type { Theme } from '../../../theme'
5+
import type { ViewType } from 'react-diff-view'
56

6-
export type DiffViewStyle = 'split' | 'unified'
77
interface DiffViewStyleOptionsProps {
8-
handleViewStyleChange: (style: DiffViewStyle) => void
9-
diffViewStyle: DiffViewStyle
8+
handleViewStyleChange: (style: ViewType) => void
9+
diffViewStyle: ViewType
1010
theme?: Theme
1111
}
1212
const DiffViewStyleOptions = styled(

0 commit comments

Comments
 (0)