Skip to content

Negative numbers cannot be used in @default #393

@herberthobregon

Description

@herberthobregon

Description

When defining a model field with a negative number as the default value, the TypeScript schema generation fails.

Example

model users {
  id String @id() @default(cuid())
  tz Int @default(-6) @db.SmallInt()
}
pnpm zen generate
✖ Generating TypeScript schema
Error: Debug Failure. False expression: Negative numbers should be created in combination with createPrefixUnaryExpression
    at Object.createNumericLiteral (/Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/lib/typescript.js:25412:11)
    at TsSchemaGenerator.createLiteralNode (file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:1335:154)
    at TsSchemaGenerator.createDataFieldObject (file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:1060:81)
    at file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:933:172
    at Array.map (<anonymous>)
    at TsSchemaGenerator.createDataModelObject (file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:933:104)
    at file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:911:197
    at Array.map (<anonymous>)
    at TsSchemaGenerator.createModelsObject (file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:911:135)
    at TsSchemaGenerator.createSchemaObject (file:///Users/herberth/code/conectate/hx-backend/node_modules/.pnpm/@zenstackhq+sdk@3.0.0-beta.21/node_modules/@zenstackhq/sdk/dist/index.js:879:58)

Steps to Reproduce

  1. Add a field with a negative default value in a .zmodel file.
  2. Run pnpm zen generate.
  3. Observe the error during TypeScript schema generation.

Environment

• @zenstackhq/sdk: 3.0.0-beta.21
• typescript: 5.8.2
• Node.js environment with pnpm
• macOS 15.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions