From ee586477f28eb047c96b27978696ffbf7750f130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marti=CC=81n?= Date: Tue, 24 Dec 2024 11:33:01 +0100 Subject: [PATCH] Add variant to link to media value --- src/lib/isValue.ts | 7 +------ src/types/value/linkToMedia.ts | 10 +++++----- test/types/fields-linkToMedia.types.ts | 6 ++++++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/isValue.ts b/src/lib/isValue.ts index f0ac7989..b1df66c7 100644 --- a/src/lib/isValue.ts +++ b/src/lib/isValue.ts @@ -24,11 +24,6 @@ type UnknownValue = /** * Checks if a value is a link to media field. * - * @remarks - * The return value includes `OptionalLinkProperties` because - * `FilledLinkToMediaField` may be a link field, not strictly a content - * relationship field. - * * @param value - Value to check. * * @returns `true` if `value` is a link to media field, `false` otherwise. @@ -38,7 +33,7 @@ type UnknownValue = */ export const filledLinkToMedia = ( value: UnknownValue, -): value is FilledLinkToMediaField & OptionalLinkProperties => { +): value is FilledLinkToMediaField => { if (value && typeof value === "object" && !("version" in value)) { if ( "link_type" in value && diff --git a/src/types/value/linkToMedia.ts b/src/types/value/linkToMedia.ts index 281989de..0ddd5f7d 100644 --- a/src/types/value/linkToMedia.ts +++ b/src/types/value/linkToMedia.ts @@ -1,5 +1,7 @@ import type { FieldState } from "./types" +import type { OptionalLinkProperties } from "./link" + /** * A link field that points to media. * @@ -10,13 +12,12 @@ export type LinkToMediaField = type EmptyLinkToMediaField = { link_type: "Any" - text?: string -} +} & OptionalLinkProperties /** * A link that points to media. */ -export interface FilledLinkToMediaField { +export type FilledLinkToMediaField = { id: string link_type: "Media" name: string @@ -25,5 +26,4 @@ export interface FilledLinkToMediaField { size: string height?: string | null width?: string | null - text?: string -} +} & OptionalLinkProperties diff --git a/test/types/fields-linkToMedia.types.ts b/test/types/fields-linkToMedia.types.ts index 671d6b66..7233f9eb 100644 --- a/test/types/fields-linkToMedia.types.ts +++ b/test/types/fields-linkToMedia.types.ts @@ -31,6 +31,7 @@ expectType({ height: "string", width: "string", text: "string", + variant: "string", }) expectType>({ id: "string", @@ -42,6 +43,7 @@ expectType>({ height: "string", width: "string", text: "string", + variant: "string", }) expectType>({ link_type: prismic.LinkType.Any, @@ -54,6 +56,7 @@ expectType>({ height: "string", width: "string", text: "string", + variant: "string", }) /** @@ -76,13 +79,16 @@ expectType>({ expectType({ link_type: prismic.LinkType.Any, text: "string", + variant: "string", }) expectType>({ link_type: prismic.LinkType.Any, text: "string", + variant: "string", }) expectType>({ // @ts-expect-error - Filled fields cannot contain an empty value. link_type: prismic.LinkType.Any, text: "string", + variant: "string", })