Skip to content

Commit 112d41a

Browse files
authored
Record<string, any> in ts maps to JSON in clickhouse (#2317)
1 parent 6231923 commit 112d41a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

apps/framework-cli/tests/test_project/app/datamodels/index_type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ type Key<T extends string | number> = T;
33
export interface MyModel {
44
name: Key<string>;
55
custom_properties: {
6-
[key: string]: any;
6+
[key: symbol]: any;
77
}
88
}

packages/ts-moose-lib/src/dataModels/typeConvert.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@ const handleStringType = (
226226
}
227227
};
228228

229+
const isStringAnyRecord = (t: ts.Type, checker: ts.TypeChecker): boolean => {
230+
const indexInfos = checker.getIndexInfosOfType(t);
231+
if (indexInfos && indexInfos.length === 1) {
232+
const indexInfo = indexInfos[0];
233+
return (
234+
indexInfo.keyType == checker.getStringType() &&
235+
indexInfo.type == checker.getAnyType()
236+
);
237+
}
238+
239+
return false;
240+
};
241+
229242
const tsTypeToDataType = (
230243
t: ts.Type,
231244
checker: TypeChecker,
@@ -238,9 +251,9 @@ const tsTypeToDataType = (
238251

239252
const aggregationFunction = handleAggregated(t, checker, fieldName, typeName);
240253

241-
// this looks nicer if we turn on experimentalTernaries in prettier
242254
const dataType: DataType =
243255
isEnum(nonNull) ? enumConvert(nonNull)
256+
: isStringAnyRecord(nonNull, checker) ? "JSON"
244257
: checker.isTypeAssignableTo(nonNull, checker.getStringType()) ?
245258
handleStringType(nonNull, checker, fieldName)
246259
: isNumberType(nonNull, checker) ?

0 commit comments

Comments
 (0)