fix(typescript): apply exactOptionalPropertyTypes to inline request types#16978
fix(typescript): apply exactOptionalPropertyTypes to inline request types#16978Swimburger wants to merge 2 commits into
Conversation
…ypes Optional request-wrapper properties now emit `T | undefined` when `noSerdeLayer: true`, mirroring the object type generator.
…hare stripTopLevelUndefined Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
The PR extracts the top-level-undefined-stripping helper into a shared util and applies the exactOptionalPropertyTypes widening to inline request types when the serde layer is off. The core generator change is small, correctly gated, and handles the double-undefined file upload case. The regenerated seed outputs are consistent with the change. No blocking issues found.
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Description
Supersedes / completes #16972 (whose branch lives on a fork I can't push to). Includes the original commit plus the follow-ups needed to make the change land consistently.
With
noSerdeLayer: true, optional properties on inline request types (client/requests/*) are now generated aspropName?: Type | undefined, matching what the object type generator already does for type declarations. This satisfiesexactOptionalPropertyTypes: trueso callers can explicitly set optional fields toundefined.Changes Made
GeneratedRequestWrapperImpl.ts): when a property is optional and the serde layer is off, widen its type node toT | undefined(same!includeSerdeLayergate the object generator uses). (original fix(typescript): apply exactOptionalPropertyTypes to inline request types #16972 change)undefinedon optional file uploads (Devin Review finding on fix(typescript): apply exactOptionalPropertyTypes to inline request types #16972):getFileParameterTypealready appends| undefinedfor optional files, so the naive widening producedUploadable | undefined | undefined. Now strip any top-levelundefinedbefore re-adding it.stripTopLevelUndefinedutil: extracted the strip logic (previously private methods inGeneratedObjectTypeImpl) into@fern-typescript/commons/codegen-utils/stripTopLevelUndefined.ts, and refactored both the object type generator and request wrapper generator to use it — so both emission paths handle widening identically.versions.ymlentry intogenerators/typescript/sdk/changes/unreleased/apply-exact-optional-to-request-types.yml(type: fix);versions.ymlreverted to matchmain(versioning is automation-driven).file-upload/.../OptionalArgsRequest.ts:export interface OptionalArgsRequest { image_file?: core.file.Uploadable | undefined; // stays single — no double undefined - request?: unknown; + request?: unknown | undefined; }Testing
pnpm turbo run compile --filter @fern-typescript/*— passesbiome checkon all changed generator sources — passespnpm seed test --generator ts-sdk --local --skip-scripts— 225/225 fixtures passLink to Devin session: https://app.devin.ai/sessions/a0d61f68646b4af789c322fda6cb4fc4
Requested by: @Swimburger