pydantic-to-typescript icon indicating copy to clipboard operation
pydantic-to-typescript copied to clipboard

Custom __root__ dict models generated as empty types

Open mikewilli opened this issue 2 years ago • 1 comments

I am seeing an issue when generating typescript types from pydantic models that consist of a custom root dict field, like this:

Pydantic model:

class CustomModel(BaseModel):
    __root__: dict[str, int]

Expected result:

export interface CustomModel {
  [k: string]: int;
}

Actual result:

export interface CustomModel {}

I can work around this issue by setting extra=Extra.allow on the pydantic model, but I would rather avoid having to do this. This comment explains why the workaround is necessary.

Python 3.10 Pydantic 1.10 pydantic-to-typescript 1.0.10

mikewilli avatar Aug 10 '23 22:08 mikewilli

try add a CustomModel class Config: validate_assignment = True allow_population_by_field_name = True

marcelomarkus avatar Sep 05 '23 19:09 marcelomarkus