Skip to content

Commit 862bbb8

Browse files
authored
Merge pull request #30 from kylemilloy/master
Use `unknown` instead of `any` as the value to fallback to when the type is not known
2 parents 9a11e2c + 6fd0667 commit 862bbb8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

django_typomatic/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __map_choices_to_union(field_type, choices):
7878
'''
7979
if not choices:
8080
_LOG.warning(f'No choices specified for Serializer Field: {field_type}')
81-
return 'any'
81+
return 'unknown'
8282

8383
return ' | '.join(f'"{key}"' if type(key) == str else str(key) for key in choices.keys())
8484

@@ -89,7 +89,7 @@ def __map_choices_to_enum(enum_name, field_type, choices):
8989
'''
9090
if not choices:
9191
_LOG.warning(f'No choices specified for Serializer Field: {field_type}')
92-
return 'any'
92+
return 'unknown'
9393

9494
choices_enum = f"export enum {enum_name} {{\n"
9595
for key, value in choices.items():
@@ -120,11 +120,11 @@ def __process_field(field_name, field, context, serializer, trim_serializer_outp
120120
ts_type = __get_trimmed_name(
121121
field_type.__name__, trim_serializer_output)
122122
elif field_type in __field_mappings[context]:
123-
ts_type = __field_mappings[context].get(field_type, 'any')
123+
ts_type = __field_mappings[context].get(field_type, 'unknown')
124124
elif (context in __mapping_overrides) and (serializer in __mapping_overrides[context]) \
125125
and field_name in __mapping_overrides[context][serializer]:
126126
ts_type = __mapping_overrides[context][serializer].get(
127-
field_name, 'any')
127+
field_name, 'unknown')
128128
elif field_type == serializers.PrimaryKeyRelatedField:
129129
ts_type = "number | string"
130130
elif hasattr(field, 'choices') and enum_choices:
@@ -133,7 +133,7 @@ def __process_field(field_name, field, context, serializer, trim_serializer_outp
133133
elif hasattr(field, 'choices'):
134134
ts_type = __map_choices_to_union(field_type, field.choices)
135135
else:
136-
ts_type = mappings.get(field_type, 'any')
136+
ts_type = mappings.get(field_type, 'unknown')
137137
if is_many:
138138
ts_type += '[]'
139139

0 commit comments

Comments
 (0)