Skip to content

Commit

Permalink
correct number field parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Jun 2, 2024
1 parent 6cb0fa1 commit ce62c92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/codegen/makeGetter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect } from "vitest";
import f from "../test/fixtures/fieldDefinition";
import { makeGetter } from "./makeGetter";
import { FieldDefinition } from "..";
import f from "../test/fixtures/fieldDefinition.js";
import { makeGetter } from "./makeGetter.js";
import { FieldDefinition } from "../index.js";

function run(field: Partial<FieldDefinition> = {}): string {
return makeGetter(f(field), [
Expand Down Expand Up @@ -116,6 +116,12 @@ describe("makeGetter", () => {
},
`"field_name"`,
],
[
{
type: "number",
},
"parseFloat(String(",
],
])("%s => `%s`", (field, expected) => {
expect(run(field)).toContain(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/makeGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getBody(field: FieldDefinition, tables: Table[]): string {
const query = `this.getField<${rawType}>("${field.name}")`;

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

if (field.type === "single_select") {
Expand Down

0 comments on commit ce62c92

Please sign in to comment.