Skip to content

Field with default value becomes optional on the TypeScript interface #1

Closed
@alythobani

Description

@alythobani

Copied over from phillipdupuis#28:

Example:

class MyModel(BaseModel):
  my_bool_property: bool = False

Convert to TypeScript and see output:

interface MyModel {
  my_bool_property?: bool;
}

I believe that the interface shouldn't define the property as optional, since Pydantic will ensure it is hydrated with the default value of false if it's not provided when creating models, e.g.:

newModel = MyModel()
assert newModel.my_bool_property is False  # assertion passes

Expected TypeScript interface:

interface MyModel {
  my_bool_property: bool;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions