From 5922ace3be8933c866427d1d907d61b8579c825a Mon Sep 17 00:00:00 2001 From: Bu Kinoshita <6929565+bukinoshita@users.noreply.github.com> Date: Tue, 11 Jul 2023 17:45:26 -0300 Subject: [PATCH] fix: Types (#137) --- package.json | 3 ++- .../create-email-options.interface.ts | 20 +++++++------------ yarn.lock | 5 +++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index f275c846..02009ae9 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "homepage": "https://github.com/resend-inc/resend-node#readme", "dependencies": { "@react-email/render": "0.0.7", - "axios": "1.4.0" + "axios": "1.4.0", + "type-fest": "3.13.0" }, "devDependencies": { "@types/jest": "29.5.3", diff --git a/src/emails/interfaces/create-email-options.interface.ts b/src/emails/interfaces/create-email-options.interface.ts index 09585bf5..e02f9f6e 100644 --- a/src/emails/interfaces/create-email-options.interface.ts +++ b/src/emails/interfaces/create-email-options.interface.ts @@ -1,5 +1,6 @@ import * as React from 'react'; import { PostOptions } from '../../common/interfaces'; +import { RequireAtLeastOne } from 'type-fest'; interface CreateEmailBaseOptions { attachments?: Attachment[]; @@ -8,25 +9,18 @@ interface CreateEmailBaseOptions { from: string; headers?: Record; react?: React.ReactElement | React.ReactNode | null; + html?: string; + text?: string; reply_to?: string | string[]; subject: string; tags?: Tag[]; to: string | string[]; } -interface CreateEmailWithHtmlOptions extends CreateEmailBaseOptions { - html: string; - text?: string; -} - -interface CreateEmailWithTextOptions extends CreateEmailBaseOptions { - html?: string; - text: string; -} - -export type CreateEmailOptions = - | CreateEmailWithHtmlOptions - | CreateEmailWithTextOptions; +export type CreateEmailOptions = RequireAtLeastOne< + CreateEmailBaseOptions, + 'react' | 'html' | 'text' +>; export interface CreateEmailRequestOptions extends PostOptions {} diff --git a/yarn.lock b/yarn.lock index 5a6f70da..276a228e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2743,6 +2743,11 @@ type-detect@4.0.8: resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== +type-fest@3.13.0: + version "3.13.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-3.13.0.tgz#b088347ae73779a750c461694b264340c4c8c0d7" + integrity sha512-Gur3yQGM9qiLNs0KPP7LPgeRbio2QTt4xXouobMCarR0/wyW3F+F/+OWwshg3NG0Adon7uQfSZBpB46NfhoF1A== + type-fest@^0.21.3: version "0.21.3" resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz"