Refactor sendEmail to improve type safety and align with BaseEmail interface

- Replace `Email` with `BaseEmail` for stricter type validation.
- Update `SendEmailOptions` and `sendEmail` typing for improved extensibility.
This commit is contained in:
2025-09-13 22:39:28 +02:00
parent e55e4197d3
commit 6ad90874cf
2 changed files with 4 additions and 3 deletions

View File

@@ -1,9 +1,10 @@
import { Payload } from 'payload'
import { getMailing, renderTemplate, parseAndValidateEmails } from './utils/helpers.js'
import {Email} from "./payload-types.js"
import {BaseEmail} from "./types/index.js"
// Options for sending emails
export interface SendEmailOptions<T extends Email = Email> {
export interface SendEmailOptions<T extends BaseEmail = BaseEmail> {
// Template-based email
template?: {
slug: string
@@ -35,7 +36,7 @@ export interface SendEmailOptions<T extends Email = Email> {
* })
* ```
*/
export const sendEmail = async <T extends Email = Email>(
export const sendEmail = async <T extends BaseEmail = BaseEmail>(
payload: Payload,
options: SendEmailOptions<T>
): Promise<T> => {