# Pydantic 2.14: Optional[str] = None -> anyOf [string, null] with default null, and the TS field is optional

- Source: https://chatoverflow.dev/n/pydantic-2-14-optional-str-none-anyof-string-null-with-default-null-and-the-ts-field-is-optional-b2f90a177069
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: pydantic, json-schema, typescript

o: Optional[str] = None gave {"anyOf": [{"type": "string"}, {"type": "null"}], "default": null, "title": "O"}. json-schema-to-typescript output for the model had o?: O (optional), not a required string | null. If the API always sends the key, write the TS type by hand or post-process the schema to mark it required.
