From 4dcbc1446a1800aac544f56fcb8e002f5acc8824 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 23:38:46 +0200 Subject: [PATCH] Fix variables field type to support all JSON-compatible values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace restrictive Record with flexible JSONValue type for variables field - Add JSONValue type alias that matches Payload's JSON field type specification - Support string, number, boolean, objects, arrays, null, and undefined for variables - Update both BaseEmailDocument and QueuedEmail interfaces consistently - Update documentation to reflect JSONValue support Fixes type constraint error where customer Email.variables field type (string | number | boolean | {...} | unknown[] | null | undefined) was not assignable to Record. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CUSTOM-TYPES.md | 5 ++++- src/types/index.ts | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CUSTOM-TYPES.md b/CUSTOM-TYPES.md index 5dafa06..fefd8f9 100644 --- a/CUSTOM-TYPES.md +++ b/CUSTOM-TYPES.md @@ -53,6 +53,9 @@ Your Payload configuration determines which types are used. The plugin automatic The base interfaces provided by the plugin: ```typescript +// JSON value type that matches Payload's JSON field type +type JSONValue = string | number | boolean | { [k: string]: unknown } | unknown[] | null | undefined + interface BaseEmailDocument { id: string | number template?: any @@ -64,7 +67,7 @@ interface BaseEmailDocument { subject: string html: string text?: string | null - variables?: Record | null + variables?: JSONValue // Supports any JSON-compatible value scheduledAt?: string | null sentAt?: string | null status?: 'pending' | 'processing' | 'sent' | 'failed' | null diff --git a/src/types/index.ts b/src/types/index.ts index 1e42760..bf8d462 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,6 +2,9 @@ import { Payload } from 'payload' import type { CollectionConfig, RichTextField } from 'payload' import { Transporter } from 'nodemailer' +// JSON value type that matches Payload's JSON field type +export type JSONValue = string | number | boolean | { [k: string]: unknown } | unknown[] | null | undefined + // Generic base interfaces that work with any ID type and null values export interface BaseEmailDocument { id: string | number @@ -14,7 +17,7 @@ export interface BaseEmailDocument { subject: string html: string text?: string | null - variables?: Record | null + variables?: JSONValue scheduledAt?: string | null sentAt?: string | null status?: 'pending' | 'processing' | 'sent' | 'failed' | null @@ -84,7 +87,7 @@ export interface QueuedEmail { subject: string html: string text?: string | null - variables?: Record | null + variables?: JSONValue scheduledAt?: string | null sentAt?: string | null status: 'pending' | 'processing' | 'sent' | 'failed'