Skip to content

[BUG]: PgSchema enum type changed from typeof pgEnum to any #4421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
nyates42 opened this issue Apr 17, 2025 · 1 comment · Fixed by #4450
Closed
1 task done

[BUG]: PgSchema enum type changed from typeof pgEnum to any #4421

nyates42 opened this issue Apr 17, 2025 · 1 comment · Fixed by #4450
Assignees
Labels
bug Something isn't working

Comments

@nyates42
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.42.0

What version of drizzle-kit are you using?

0.31.0

Other packages

No response

Describe the Bug

[BUG] Breaking change in v0.42.0: PgSchema enum type definition causing NestJS/TypeScript errors

Describe the Bug

Undesired Behavior

After upgrading to drizzle-orm v0.42.0, the type definition for PgSchema.enum has changed from typeof pgEnum to any in pg-core/schema.d.ts. This breaks strict TypeScript type checking due to use of any.

We use drizzle-kit introspect to generate our schema file from our existing PostgreSQL database.

Steps to Reproduce for our use-case

  1. Have a NestJS application using PostgreSQL with Drizzle ORM
  2. Use drizzle-kit introspect to generate schema from a database with enums:
// Generated schema.ts
export const priorityLevel = mySchema.enum("priority_level", [
  'critical',
  'high',
  'medium',
  'low',
  'trivial'
]);
  1. Use these generated enums in NestJS entities:
@ApiProperty({
    description: 'Task priority level',
    enum: priorityLevel.enumValues,
    nullable: true,
})
public priority!: string | null;
  1. Upgrade from v0.41.0 to v0.42.0
  2. TypeScript compilation fails due to enum type issues
  3. Running drizzle-kit introspect again doesn't help as it still generates string arrays for enums

Desired Result

The enum type definition should maintain proper typing while supporting both TypeScript enums and string unions, rather than using any. This would preserve type safety while allowing the new enum functionality introduced in v0.42.0, regardless of whether the enums are manually defined or generated via introspection.

Additional Information

  • Database: PostgreSQL
  • TypeScript version: 5.7.3
  • NestJS version: 11.0.0
  • Node.js version: 22.13.1

Relevant Code

Previous type definition (pre-v0.42.0):

export declare class PgSchema<TName extends string = string> implements SQLWrapper {
    enum: typeof pgEnum;
}

Current type definition (v0.42.0):

export declare class PgSchema<TName extends string = string> implements SQLWrapper {
    enum: any;
}

Workaround

Currently rolling back to the previous version of drizzle-orm.

@nyates42 nyates42 added the bug Something isn't working label Apr 17, 2025
@abielzulio
Copy link

abielzulio commented Apr 22, 2025

can confirm. any idea/solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants