-
Couldn't load subscription status.
- Fork 57
Description
Describe the Bug
There's a type mismatch between the TypeScript interfaces and the actual runtime behavior for contact name fields first_name and last_name. There are two separate but related problems:
- GET Response Types Don't Match Reality
The GetContactResponseSuccess interface declares first_name and last_name as optional strings. However, the API actually returns null when these fields are not set, not undefined, breaking the TypeScript contract.
- UPDATE Options Don't Support Clearing Fields
The UpdateContactOptions interface also declares firstName and lastName as optional strings. But in practice, passing null is the only way to clear these fields:
- Passing an explicit
undefined(or omitting the field) leaves the existing value unchanged - Passing an empty string
''sets the field to an empty string (notnull) - Passing
nullclears the field back tonull
This null behavior isn't reflected in the types, so TypeScript users have no way to clear these fields without a type assertion.
Link to the code that reproduces this issue
To Reproduce
The test script linked above demonstrates all these behaviors. To run it yourself:
- Pass a real API key to
Resend()in place of my redacted one - Replace my audience ID with one of your own
- Place the script in the root of your
resend-noderepo pnpm buildnode ./contacts-test-script.mjs
Expected Behavior
Here are the possible solutions that have come to my mind, but I'm not sure which approach you'd prefer:
- Update the TypeScript interfaces to include
nullwhere applicable- Change
first_name?: stringtofirst_name: string | nullin GET responses - Change
firstName?: stringtofirstName?: string | nullin UPDATE options
- Change
- Normalize
nulltoundefinedat the SDK level—though this might be tricky for UPDATE requests where distinguishing between "not provided" and "explicitly clear this field" is important - Change the API behavior to not return
nullin GET responses (though this would be a breaking API change) - Treat
nulland empty strings the same—though the current distinction might be intentional
I lean toward option 1 (updating the interfaces), personally, as it's the least breaking and accurately reflects the API's actual behavior.
What's your node version? (if relevant)
v24.8.0