Skip to content

Conversation

@phall1
Copy link

@phall1 phall1 commented Jan 3, 2026

Problem

When a schema has "default": {}, the generated TypeScript code was:

default: () => {} as const

This is invalid JavaScript/TypeScript because {} after an arrow is parsed as an empty block statement (returning undefined), not an object literal.

Solution

Wrap the JSON.stringify output in parentheses:

default: () => ({} as const)

Example

OpenAPI schema:

{
  "task_status_counts": {
    "type": "object",
    "additionalProperties": { "type": "integer" },
    "default": {}
  }
}

Before (invalid):

S.optionalWith(S.Record(...), { nullable: true, default: () => {} as const })

After (valid):

S.optionalWith(S.Record(...), { nullable: true, default: () => ({} as const) })

When a schema has `default: {}`, the generated code was:
  `() => {} as const`

This is invalid because `{}` is parsed as an empty block statement,
not an object literal. Fixed by wrapping in parentheses:
  `() => ({} as const)`
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.

1 participant