Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ export class FileUploadRequestParameter extends AbstractRequestParameter {
}

private getReferenceToProperty(propertyName: string): ts.Expression {
return ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(this.getRequestParameterName()),
propertyName
);
const requestIdentifier = ts.factory.createIdentifier(this.getRequestParameterName());
if (!this.isValidIdentifier(propertyName)) {
return ts.factory.createElementAccessExpression(
requestIdentifier,
ts.factory.createStringLiteral(propertyName)
);
}
return ts.factory.createPropertyAccessExpression(requestIdentifier, propertyName);
}

private isValidIdentifier(name: string): boolean {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do we have utilities to do this elsewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call – I found that @fern-typescript/commons already uses esutils.keyword.isIdentifierNameES6 in getPropertyKey.ts for this exact purpose. I've added a shared isValidIdentifier utility to the commons package and updated this file to use it instead of the custom regex. This gives us full ES6 identifier coverage and keeps the codebase consistent.

return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
}
}
10 changes: 10 additions & 0 deletions generators/typescript/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json
- version: 3.37.1
changelogEntry:
- summary: |
Fix file upload request parameters to use bracket notation for property names that are not valid JavaScript identifiers (e.g., header names with hyphens like `X-Custom-Header`).
Previously, the generator produced invalid JavaScript like `request.X - Custom - Header` which was interpreted as subtraction operations.
Now it correctly generates `request["X-Custom-Header"]`.
type: fix
createdAt: "2025-12-08"
irVersion: 62

- version: 3.37.0
changelogEntry:
- summary: |
Expand Down
Loading