quicktype
quicktype copied to clipboard
Python fails for Union[bool, float]
If I generate python code from a typescript definition like:
value: boolean | string | number | null;
The corresponding python code parser has something like:
value = from_union(
[from_none, from_float, from_bool, from_str], obj.get("value")
)
So it tries float before boolean, even though boolean is mentioned in the definition first. And since False and True both can be converted to floats in Python, you end up with 1.0 or 0.0 as a value after conversion instead of True or False