Skip to content

Literal field becomes optional in typescript #36

Open
@jcampbell

Description

@jcampbell

If I define a property using a Literal with a default value, it shows as optional in typescript. This is similar to #28 but, I think it should be treated differently because the value must be set, even by a client (the property is used as a discriminator in a union).

from typing import Literal
from pydantic import BaseModel


class MyModel(BaseModel):
  my_bool_property: Literal[False] = False

renders into

/* tslint:disable */
/* eslint-disable */
/**
/* This file was automatically generated from pydantic models by running pydantic2ts.
/* Do not modify it by hand - just update the pydantic models and then re-run the script
*/

export interface MyModel {
  my_bool_property?: false;
}

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