Skip to content

Commit

Permalink
improve number-type getters
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Apr 15, 2024
1 parent a427c7c commit e85e4e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/codegen/makeGetter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ describe("makeGetter", () => {
`<({ id: 1, value: "the_option_name", color: "red" } | { id: 2, value: "the_option_name_2", color: "blue" })>`,
],
[{ type: "number" }, `: number {`],
[
{
type: "rollup",
formula_type: "number",
},
`: number {`,
],
[
{
type: "rollup",
formula_type: "number",
},
`parseFloat(`,
],
])("%s => `%s`", (field, expected) => {
expect(run(field)).toContain(expected);
});
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/makeGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getReturnType(field: FieldDefinition, tables: Table[]): string {
.join(" | ");
}

if (field.type === "number") {
if (field.type === "number" || field.formula_type === "number") {
return "number";
}

Expand All @@ -49,7 +49,7 @@ function getBody(field: FieldDefinition, tables: Table[]): string {
const rawType = makeFieldType(field);
const query = `this.getField<${rawType}>("${field.name}")`;

if (field.type === "number") {
if (field.type === "number" || field.formula_type === "number") {
return `return parseFloat(${query}.toString());`;
}

Expand Down

0 comments on commit e85e4e6

Please sign in to comment.