Skip to content

Commit efbb5b1

Browse files
committed
fix prop typing generation
1 parent 5194e18 commit efbb5b1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

@plotly/dash-generator-test-component-typescript/src/props.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type TypescriptComponentProps = {
2525
array_obj?: {a: string}[];
2626
array_any?: any[];
2727
enum_string?: 'one' | 'two';
28+
enum_number?: 2 | 3 | 4 | 5 | 6;
2829
union?: number | string;
2930
union_shape?: {a: string} | string;
3031
array_union_shape?: ({a: string} | string)[];

dash/development/_py_prop_typing.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,17 @@ def _get_literal_value(value):
103103
if value is None:
104104
return "None"
105105

106+
if isinstance(value, str):
107+
value = json.loads(value.replace("'", '"'))
108+
106109
if isinstance(value, bool):
107110
return str(value)
108111

109112
return json.dumps(value)
110113

111114

112115
def generate_enum(type_info, *_):
113-
values = [
114-
_get_literal_value(json.loads(v["value"].replace("'", '"')))
115-
for v in type_info["value"]
116-
if v
117-
]
116+
values = [_get_literal_value(v["value"]) for v in type_info["value"] if v]
118117
return f"Literal[{', '.join(values)}]"
119118

120119

0 commit comments

Comments
 (0)