Valentin W
Valentin W
DTDrizzle Team
Created by Valentin W on 8/31/2024 in #help
Numeric type returns number instead of string as defined in TypeScript
Hello, I'm trying Drizzle ORM with PostgreSQL and TypeScript. I've noticed a discrepancy between the TypeScript definitions and the actual runtime behavior for numeric fields. Schema definition:
export const bankrolls = pgTable('bankrolls', {
id: uuid('id').primaryKey(),
name: varchar('name'),
startingCapital: numeric('starting_capital', { precision: 8, scale: 2 }),
});
export const bankrolls = pgTable('bankrolls', {
id: uuid('id').primaryKey(),
name: varchar('name'),
startingCapital: numeric('starting_capital', { precision: 8, scale: 2 }),
});
The request
async all(userId: string): Promise<BankrollsViewModel[]> {
const result = await this.sqlConnection
.select()
.from(bankrolls)
.where(eq(bankrolls.userId, userId));
return result;
}
async all(userId: string): Promise<BankrollsViewModel[]> {
const result = await this.sqlConnection
.select()
.from(bankrolls)
.where(eq(bankrolls.userId, userId));
return result;
}
The type of result is inferred as:
{
id: string;
name: string;
startingCapital: string; // Note: string
}[]
{
id: string;
name: string;
startingCapital: string; // Note: string
}[]
However, when I log the actual value of startingCapital, it's a number:
console.log(typeof result[0].startingCapital); // Outputs: "number"
console.log(typeof result[0].startingCapital); // Outputs: "number"
Expected behavior: startingCapital should be a string to match the TypeScript definition. Actual behavior: startingCapital is a number. My version are : "drizzle-orm": "^0.33.0", "drizzle-kit": "^0.24.2" I just want the type and runtime value to match, regardless of whether it's a string or a number
1 replies