Skip to content

Commit 691d07c

Browse files
refactor: use type guard
1 parent 1187f5d commit 691d07c

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

src/component/panels/SummaryPanel/SummaryPanel.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getLinkDelta, getLinkDim } from 'nmr-correlation';
1010
import { memo, useCallback, useMemo, useState } from 'react';
1111
import { FaFlask, FaSlidersH } from 'react-icons/fa';
1212

13+
import { isSpectrum2D } from '../../../data/data2d/Spectrum2D/isSpectrum2D.ts';
1314
import {
1415
findRange,
1516
findSignal1D,
@@ -148,13 +149,9 @@ function SummaryPanel() {
148149
// try to find a link which contains the belonging 2D signal in the spectra in view
149150
if (
150151
correlation.link.some((link: Link) => {
151-
const spectrum = findSpectrum(
152-
spectraData,
153-
link.experimentID,
154-
true,
155-
) as Spectrum2D;
152+
const spectrum = findSpectrum(spectraData, link.experimentID, true);
156153

157-
if (!spectrum) return false;
154+
if (!isSpectrum2D(spectrum)) return false;
158155

159156
return findSignalMatch1D(
160157
spectrum,
@@ -181,10 +178,10 @@ function SummaryPanel() {
181178
spectraData,
182179
firstLink2D.experimentID,
183180
true,
184-
) as Spectrum2D;
181+
);
185182
// correlation is represented by a 2D signal
186183

187-
if (!spectrum) return false;
184+
if (!isSpectrum2D(spectrum)) return false;
188185

189186
if (
190187
findSignalMatch2D(
@@ -202,13 +199,9 @@ function SummaryPanel() {
202199
// try to find a link which contains the belonging 2D signal in the spectra in view
203200
else if (
204201
correlation.link.some((link: any) => {
205-
const spectrum = findSpectrum(
206-
spectraData,
207-
link.experimentID,
208-
true,
209-
) as Spectrum2D;
202+
const spectrum = findSpectrum(spectraData, link.experimentID, true);
210203

211-
if (!spectrum) return false;
204+
if (!isSpectrum2D(spectrum)) return false;
212205

213206
return findSignalMatch2D(
214207
spectrum,

0 commit comments

Comments
 (0)