fix(typescript): add null/undefined guard to validateAndTransformExtendedObject #10751
+30
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes a regression where
validateAndTransformExtendedObjectin the TypeScript generator's runtime was missing a null/undefined guard, causing "Cannot convert undefined or null to object" errors when parsing extended object schemas.Context: This bug was originally fixed in PR #10214 (CLI v0.101.3) but was accidentally reverted when the docs-yml SDK was regenerated. Since
packages/cli/configuration/src/docs-yml/schemas/sdk/is generated code, this PR fixes the issue at the source - in the TypeScript generator's runtime - so it won't be overwritten on future regenerations.Reported by: [email protected] via Slack
Devin session: https://app.devin.ai/sessions/7086562bf0844761889ba0feaea8354e
Changes Made
isPlainObject()validation check tovalidateAndTransformExtendedObjectbefore callingObject.keys()value: unknowninstead ofvalue: objectfor safer type checkingbreadcrumbsPrefixparameter for better error messages in validation failuresas object) when calling the functionTesting
pnpm run check)Important Notes for Reviewers
Incomplete investigation: The original stack trace mentioned both
validateAndTransformExtendedObjectandvalidateAndTransformUndiscriminatedUnion. This PR only fixes the former - please verify if the latter also needs a similar guard.Follow-up required: After this PR merges and the generator is published, a follow-up PR will be needed to:
fern/apis/docs-yml/generators.ymlto use the new generator version (3.33.1)Seed tests: Consider running TypeScript generator seed tests before merging, as this change affects a core schema validation function used across all generated TypeScript SDKs.
Type safety improvement: Changing
value: objecttovalue: unknownis technically a breaking change in the function signature, but it's safer and more correct. The guard ensures we only proceed with actual objects.