Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: improve type errors for audience -> segments transition#815

Merged
gabrielmfern merged 1 commit into
canaryfrom
feat/improve-type-handling-for-segment-audience-duality
Jan 27, 2026
Merged

feat: improve type errors for audience -> segments transition#815
gabrielmfern merged 1 commit into
canaryfrom
feat/improve-type-handling-for-segment-audience-duality

Conversation

@gabrielmfern

@gabrielmfern gabrielmfern commented Jan 27, 2026

Copy link
Copy Markdown
Member

Uses function overloads instead of never to better handle type errors:

bad error example:

resend.contacts.create({
  email: '',
  unsubscribed: false,
  audienceId: '97c676d8-2f6d-459f-bf5c-599c274d7505',
  segments: [{ id: '97c676d8-2f6d-459f-bf5c-599c274d7505' }],
  // 1. Type '{ id: string; subscription: string; }[]' is not assignable to type '{ id: string; subscription: "opt_in" | "opt_out"; }[]'.
  //      Type '{ id: string; subscription: string; }' is not assignable to type '{ id: string; subscription: "opt_in" | "opt_out"; }'.
  //        Types of property 'subscription' are incompatible.
  //          Type 'string' is not assignable to type '"opt_in" | "opt_out"'. [2322]
  //    create-contact-options.interface.ts:32:3: The expected type comes from property 'topics' which is declared here on type 'CreateContactOptions | LegacyCreateContactOptions'
  topics: [
    { id: 'f9f21256-5f03-4900-be6e-503534093ed6', subscription: 'opt_in' },
  ],
});

after using function overloads:

// 1. No overload matches this call.
//      Overload 1 of 2, '(paylaod: CreateContactOptions, options?: CreateContactRequestOptions | undefined): Promise<CreateContactResponse>', gave the following error.
//        Object literal may only specify known properties, and 'audienceId' does not exist in type 'CreateContactOptions'.
//      Overload 2 of 2, '(paylaod: LegacyCreateContactOptions, options?: CreateContactRequestOptions | undefined): Promise<CreateContactResponse>', gave the following error.
//        Object literal may only specify known properties, and 'segments' does not exist in type 'LegacyCreateContactOptions'. [2769]
//    contacts.ts:51:9: The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
resend.contacts.create({
  email: '',
  unsubscribed: false,
  audienceId: '97c676d8-2f6d-459f-bf5c-599c274d7505',
  segments: [{ id: '97c676d8-2f6d-459f-bf5c-599c274d7505' }],
  topics: [
    { id: 'f9f21256-5f03-4900-be6e-503534093ed6', subscription: 'opt_in' },
  ],
});

@gabrielmfern gabrielmfern self-assigned this Jan 27, 2026
@gabrielmfern gabrielmfern requested a review from a team as a code owner January 27, 2026 15:23
@pkg-pr-new

pkg-pr-new Bot commented Jan 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/resend/resend-node/resend@815

commit: 9bedad1

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@gabrielmfern gabrielmfern merged commit 98a2747 into canary Jan 27, 2026
14 checks passed
@gabrielmfern gabrielmfern deleted the feat/improve-type-handling-for-segment-audience-duality branch January 27, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants