From 5be2880184337515ed1502e574ce546146c0c61f Mon Sep 17 00:00:00 2001 From: gestchild Date: Fri, 31 Jan 2025 16:22:58 +0000 Subject: [PATCH] fix typing errors --- common/services/prismic/link-resolver.test.ts | 20 +++++++++---------- common/services/prismic/link-resolver.ts | 15 +++++++------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/common/services/prismic/link-resolver.test.ts b/common/services/prismic/link-resolver.test.ts index 1337b49359..1cbf61a2a4 100644 --- a/common/services/prismic/link-resolver.test.ts +++ b/common/services/prismic/link-resolver.test.ts @@ -1,4 +1,4 @@ -import linkResolver from './link-resolver'; +import linkResolver, { HighlightTourType } from './link-resolver'; // We want to be able to pass in either Prismic or Content API content types test.each([ @@ -26,7 +26,7 @@ test.each([ doc: { type: 'Exhibition highlight tour', uid: '1', - highlightTourType: 'text', + highlightTourType: 'text' as HighlightTourType, }, path: '/guides/exhibitions/1/captions-and-transcripts', }, @@ -34,7 +34,7 @@ test.each([ doc: { type: 'Exhibition highlight tour', uid: '1', - highlightTourType: 'audio', + highlightTourType: 'audio' as HighlightTourType, }, path: '/guides/exhibitions/1/audio-without-descriptions', }, @@ -42,7 +42,7 @@ test.each([ doc: { type: 'Exhibition highlight tour', uid: '1', - highlightTourType: 'bsl', + highlightTourType: 'bsl' as HighlightTourType, }, path: '/guides/exhibitions/1/bsl', }, @@ -63,7 +63,7 @@ test.each([ doc: { type: 'exhibition-guides-links', uid: '1', - highlightTourType: 'text', + highlightTourType: 'text' as HighlightTourType, }, path: '/guides/exhibitions/1/captions-and-transcripts', }, @@ -71,7 +71,7 @@ test.each([ doc: { type: 'exhibition-guides-links', uid: '1', - highlightTourType: 'audio', + highlightTourType: 'audio' as HighlightTourType, }, path: '/guides/exhibitions/1/audio-without-descriptions', }, @@ -79,7 +79,7 @@ test.each([ doc: { type: 'exhibition-guides-links', uid: '1', - highlightTourType: 'bsl', + highlightTourType: 'bsl' as HighlightTourType, }, path: '/guides/exhibitions/1/bsl', }, @@ -92,7 +92,7 @@ test.each([ doc: { type: 'exhibition-guides', uid: '1', - highlightTourType: 'text', + highlightTourType: 'text' as HighlightTourType, }, path: '/guides/exhibitions/1/captions-and-transcripts', }, @@ -100,7 +100,7 @@ test.each([ doc: { type: 'exhibition-guides', uid: '1', - highlightTourType: 'audio', + highlightTourType: 'audio' as HighlightTourType, }, path: '/guides/exhibitions/1/audio-without-descriptions', }, @@ -108,7 +108,7 @@ test.each([ doc: { type: 'exhibition-guides', uid: '1', - highlightTourType: 'bsl', + highlightTourType: 'bsl' as HighlightTourType, }, path: '/guides/exhibitions/1/bsl', }, diff --git a/common/services/prismic/link-resolver.ts b/common/services/prismic/link-resolver.ts index 6eb6c100a2..94e36166bc 100644 --- a/common/services/prismic/link-resolver.ts +++ b/common/services/prismic/link-resolver.ts @@ -7,10 +7,11 @@ import { isContentType, } from './content-types'; +export type HighlightTourType = 'audio' | 'bsl' | 'text'; type Props = { uid?: string; type: string; - highlightTourType?: 'audio' | 'bsl' | 'text'; + highlightTourType?: HighlightTourType; siteSection?: SiteSection; }; @@ -18,9 +19,9 @@ type Props = { type DataProps = { uid?: string; type: string; - highlightTourType?: 'audio' | 'bsl' | 'text'; - tags: string[]; - data: { + highlightTourType?: HighlightTourType; + tags?: string[]; + data?: { relatedDocument?: { uid: string; type: string; @@ -73,9 +74,7 @@ function linkResolver(doc: Props | DataProps): string { } case 'visual-stories': if ('data' in doc) { - const { - data: { relatedDocument }, - } = doc; + const { data: { relatedDocument } = {} } = doc; if (relatedDocument?.uid) { return `/${relatedDocument.type}/${relatedDocument.uid}/visual-stories`; } else { @@ -90,7 +89,7 @@ function linkResolver(doc: Props | DataProps): string { // Prismic previews come through here. if ('tags' in doc) { - siteSection = doc.tags.find(t => isSiteSection(t)); + siteSection = doc.tags?.find(t => isSiteSection(t)); } return siteSection === uid || !siteSection // if it is a landing page or doesn't have a siteSection