Skip to content

Commit 38b6625

Browse files
fixup: avoid "as any"
1 parent 3c7170d commit 38b6625

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

browser/src/ShortTandemRepeatPage/ShortTandemRepeatAttributes.tsx

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,59 @@ import AttributeList, { AttributeListItem } from '../AttributeList'
44
import InlineList from '../InlineList'
55
import Link from '../Link'
66

7-
import { ShortTandemRepeat } from './ShortTandemRepeatPage'
7+
import { ShortTandemRepeat, RepeatUnitClassification } from './ShortTandemRepeatPage'
88

99
type ShortTandemRepeatRepeatUnitsProps = {
1010
shortTandemRepeat: ShortTandemRepeat
1111
}
1212

1313
const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRepeatUnitsProps) => {
14-
const repeatUnitsByClassification: Record<string, string[]> = {}
14+
const repeatUnitsByClassification: Partial<Record<RepeatUnitClassification, string[]>> = {}
1515
shortTandemRepeat.repeat_units.forEach((repeatUnit) => {
1616
if (repeatUnitsByClassification[repeatUnit.classification] === undefined) {
1717
repeatUnitsByClassification[repeatUnit.classification] = []
1818
}
19-
repeatUnitsByClassification[repeatUnit.classification].push(repeatUnit.repeat_unit)
19+
repeatUnitsByClassification[repeatUnit.classification]!.push(repeatUnit.repeat_unit)
2020
})
2121

2222
if (
23-
!(repeatUnitsByClassification as any).pathogenic &&
24-
!(repeatUnitsByClassification as any).benign
23+
!repeatUnitsByClassification.pathogenic &&
24+
!repeatUnitsByClassification.benign &&
25+
repeatUnitsByClassification.unknown
2526
) {
2627
return (
2728
<AttributeListItem
28-
label={`Repeat unit${(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''}`}
29+
label={`Repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
2930
>
3031
<InlineList
31-
items={(repeatUnitsByClassification as any).unknown.map((repeatUnit: string) => (
32+
items={repeatUnitsByClassification.unknown.map((repeatUnit: string) => (
3233
<span>
3334
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
3435
shortTandemRepeat.repeat_units.length > 1
3536
? `${repeatUnit} (reference)`
3637
: repeatUnit}
3738
</span>
3839
))}
39-
label={`Repeat unit${(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''}`}
40+
label={`Repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
4041
/>
4142
</AttributeListItem>
4243
)
4344
}
4445

4546
if (
46-
(repeatUnitsByClassification as any).pathogenic &&
47-
(repeatUnitsByClassification as any).pathogenic.length === 1 &&
48-
!(repeatUnitsByClassification as any).benign &&
49-
!(repeatUnitsByClassification as any).unknown
47+
repeatUnitsByClassification.pathogenic &&
48+
repeatUnitsByClassification.pathogenic.length === 1 &&
49+
repeatUnitsByClassification.benign &&
50+
repeatUnitsByClassification.unknown
5051
) {
5152
return (
5253
<>
53-
{(repeatUnitsByClassification as any).pathogenic && (
54+
{repeatUnitsByClassification.pathogenic && (
5455
<AttributeListItem
55-
label={`Repeat unit${
56-
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
57-
}`}
56+
label={`Repeat unit${repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''}`}
5857
>
5958
<InlineList
60-
items={(repeatUnitsByClassification as any).pathogenic.map((repeatUnit: string) => (
59+
items={repeatUnitsByClassification.pathogenic.map((repeatUnit: string) => (
6160
<span>
6261
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
6362
shortTandemRepeat.repeat_units.length > 1
@@ -66,7 +65,7 @@ const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRe
6665
</span>
6766
))}
6867
label={`Pathogenic repeat unit${
69-
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
68+
repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''
7069
}`}
7170
/>
7271
</AttributeListItem>
@@ -77,15 +76,15 @@ const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRe
7776

7877
return (
7978
<>
80-
{(repeatUnitsByClassification as any).pathogenic && (
79+
{repeatUnitsByClassification.pathogenic && (
8180
<AttributeListItem
8281
label={`Pathogenic repeat unit${
83-
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
82+
repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''
8483
}`}
8584
tooltip="These repeat units have been reported in the literature as pathogenic when they expand beyond a certain threshold."
8685
>
8786
<InlineList
88-
items={(repeatUnitsByClassification as any).pathogenic.map((repeatUnit: string) => (
87+
items={repeatUnitsByClassification.pathogenic.map((repeatUnit: string) => (
8988
<span>
9089
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
9190
shortTandemRepeat.repeat_units.length > 1
@@ -94,52 +93,44 @@ const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRe
9493
</span>
9594
))}
9695
label={`Pathogenic repeat unit${
97-
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
96+
repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''
9897
}`}
9998
/>
10099
</AttributeListItem>
101100
)}
102-
{(repeatUnitsByClassification as any).benign && (
101+
{repeatUnitsByClassification.benign && (
103102
<AttributeListItem
104-
label={`Benign repeat unit${
105-
(repeatUnitsByClassification as any).benign.length > 1 ? 's' : ''
106-
}`}
103+
label={`Benign repeat unit${repeatUnitsByClassification.benign.length > 1 ? 's' : ''}`}
107104
tooltip="These repeat units are regarded in the literature as benign, even when expanded."
108105
>
109106
<InlineList
110-
items={(repeatUnitsByClassification as any).benign.map((repeatUnit: string) => (
107+
items={repeatUnitsByClassification.benign.map((repeatUnit: string) => (
111108
<span>
112109
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
113110
shortTandemRepeat.repeat_units.length > 1
114111
? `${repeatUnit} (reference)`
115112
: repeatUnit}
116113
</span>
117114
))}
118-
label={`Benign repeat unit${
119-
(repeatUnitsByClassification as any).benign.length > 1 ? 's' : ''
120-
}`}
115+
label={`Benign repeat unit${repeatUnitsByClassification.benign.length > 1 ? 's' : ''}`}
121116
/>
122117
</AttributeListItem>
123118
)}
124-
{(repeatUnitsByClassification as any).unknown && (
119+
{repeatUnitsByClassification.unknown && (
125120
<AttributeListItem
126-
label={`Other repeat unit${
127-
(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''
128-
}`}
121+
label={`Other repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
129122
tooltip="These are the other repeat units detected at this locus within gnomAD samples by the call_non_ref_pathogenic_motifs.py script."
130123
>
131124
<InlineList
132-
items={(repeatUnitsByClassification as any).unknown.map((repeatUnit: string) => (
125+
items={repeatUnitsByClassification.unknown.map((repeatUnit: string) => (
133126
<span>
134127
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
135128
shortTandemRepeat.repeat_units.length > 1
136129
? `${repeatUnit} (reference)`
137130
: repeatUnit}
138131
</span>
139132
))}
140-
label={`Other repeat unit${
141-
(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''
142-
}`}
133+
label={`Other repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
143134
/>
144135
</AttributeListItem>
145136
)}

browser/src/ShortTandemRepeatPage/ShortTandemRepeatPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export type PlotRange = {
9090
stop: number
9191
}
9292

93+
export type RepeatUnitClassification = 'benign' | 'pathogenic' | 'unknown'
94+
9395
export type ShortTandemRepeat = {
9496
id: string
9597
gene: {
@@ -115,7 +117,7 @@ export type ShortTandemRepeat = {
115117
reference_repeat_unit: string
116118
repeat_units: {
117119
repeat_unit: string
118-
classification: string
120+
classification: RepeatUnitClassification
119121
}[]
120122
allele_size_distribution: AlleleSizeDistributionCohort[]
121123
genotype_distribution: GenotypeDistributionCohort[]

0 commit comments

Comments
 (0)