{"id":12774,"library":"prisma-generator-typescript-interfaces","title":"Prisma TypeScript Interfaces Generator","description":"prisma-generator-typescript-interfaces is a Prisma generator designed to create entirely standalone, zero-dependency TypeScript interface definitions directly from a Prisma schema. Its primary purpose is to provide type definitions for models, enums, and other schema elements without requiring the full `@prisma/client` package or the generated Prisma client itself. This makes the generated types ideal for use cases such as Data Transfer Objects (DTOs) in API layers, sharing types across different services in a monorepo, or any scenario where a lightweight, independent type declaration is preferred. The package is currently stable at version 3.1.0 and has seen consistent development, including several minor and patch releases, with a recent major version (v3.0.0) introducing notable breaking changes. A key differentiator is its extensive customizability, allowing users to configure types for various Prisma scalar types (like Date, BigInt, Decimal, Bytes) to either maintain compatibility with Prisma client's native types or to match common JSON serialization formats. It also provides granular control over relation handling and enum generation.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/mogzol/prisma-generator-typescript-interfaces","tags":["javascript","prisma","generator","typescript","interface","json","dto"],"install":[{"cmd":"npm install prisma-generator-typescript-interfaces","lang":"bash","label":"npm"},{"cmd":"yarn add prisma-generator-typescript-interfaces","lang":"bash","label":"yarn"},{"cmd":"pnpm add prisma-generator-typescript-interfaces","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Imports are for the *generated* TypeScript file, not the generator package itself. Path is relative to your source.","wrong":"const Person = require('../src/dto/interfaces');","symbol":"Person","correct":"import { Person } from '../src/dto/interfaces';"},{"note":"Enums are generated as named exports. Ensure `exportEnums` is not `false` in your config.","wrong":"import Gender from '../src/dto/interfaces';","symbol":"Gender","correct":"import { Gender } from '../src/dto/interfaces';"},{"note":"This example assumes a second generator instance configured with `output` and `modelSuffix` options.","symbol":"PersonJson","correct":"import { PersonJson } from '../src/dto/json-interfaces';"}],"quickstart":{"code":"/* prisma/schema.prisma */\ndatasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\ngenerator typescriptInterfaces {\n  provider = \"prisma-generator-typescript-interfaces\"\n  output   = \"../src/types/interfaces.ts\"\n  prettier = true\n}\n\nenum Gender {\n  Male\n  Female\n  Other\n}\n\nmodel User {\n  id        Int      @id @default(autoincrement())\n  email     String   @unique\n  name      String?\n  age       Int\n  gender    Gender\n  createdAt DateTime @default(now())\n  updatedAt DateTime @updatedAt\n}\n\n// Then, from your terminal:\n// npm install --save-dev prisma-generator-typescript-interfaces prisma typescript\n// npx prisma generate\n\n// --- Example Usage in a TypeScript file (e.g., src/app.ts) ---\n\nimport { User, Gender } from './types/interfaces'; // Path relative to the output\n\nconst newUser: User = {\n  id: 1,\n  email: 'test@example.com',\n  name: 'John Doe',\n  age: 30,\n  gender: Gender.Male,\n  createdAt: new Date(),\n  updatedAt: new Date()\n};\n\nfunction processUser(user: User) {\n  console.log(`Processing user: ${user.name || user.email}, Age: ${user.age}`);\n  if (user.gender === Gender.Female) {\n    console.log('User is female.');\n  }\n}\n\nprocessUser(newUser);\n","lang":"typescript","description":"This quickstart demonstrates how to configure the generator in `schema.prisma`, run the generation command, and then import and use the generated `User` interface and `Gender` enum in a TypeScript application."},"warnings":[{"fix":"Update your `generator` block in `schema.prisma`. Replace `omitRelations = true` or `optionalRelations = true` with `relations = \"none\"` or `relations = \"optional\"` respectively. Use `relations = \"required\"` for the default behavior.","message":"The `omitRelations` and `optionalRelations` options were removed and replaced by a single `relations` option. Users must migrate their configurations.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"To replicate the behavior of `BufferObject` or `ArrayObject`, you must now define a custom type. Refer to the 'Custom Types' documentation for guidance on how to define these via the `customTypes` option.","message":"The built-in `BufferObject` and `ArrayObject` types for the `bytesType` option have been removed. Attempting to use these will result in configuration errors.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade your project's TypeScript version to 4.9 or newer. Alternatively, avoid using `enumType = \"object\"` and choose a different `enumType` setting.","message":"When `enumType` is set to `\"object\"`, the generated code utilizes the TypeScript `satisfies` keyword. This introduces a breaking change for projects using TypeScript versions older than 4.9.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"If you are using Prisma v5 and require `Buffer` types for compatibility with your Prisma client, explicitly set `bytesType = \"Buffer\"` in your generator configuration in `schema.prisma`.","message":"The default type for `Bytes` fields changed from `Buffer` to `Uint8Array` to align with Prisma v6's default behavior. This is a breaking change for projects on Prisma v5 expecting `Buffer` types.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Replace `omitRelations` or `optionalRelations` with the new `relations` option. For example, use `relations = \"none\"` to omit all relations, or `relations = \"optional\"`.","cause":"The `omitRelations` option (and `optionalRelations`) was removed in version 3.0.0.","error":"Error: Unknown generator option: 'omitRelations'."},{"fix":"Remove `bytesType = \"BufferObject\"` (or `ArrayObject`) from your generator configuration. If you need this behavior, define a custom type using the `customTypes` option.","cause":"The built-in `BufferObject` and `ArrayObject` options for `bytesType` were removed in v3.0.0.","error":"TS2304: Cannot find name 'BufferObject'."},{"fix":"Upgrade your TypeScript dependency to version 4.9 or higher, or change the `enumType` option in your generator configuration to a different value.","cause":"Your project's TypeScript version is older than 4.9, and the generator's `enumType = \"object\"` configuration uses the `satisfies` keyword.","error":"TS2304: Cannot find name 'satisfies'."},{"fix":"Explicitly set `bytesType = \"Buffer\"` in your `generator typescriptInterfaces` block in `schema.prisma` if you are using Prisma v5.","cause":"The default `bytesType` changed to `Uint8Array` in v2.0.0 for Prisma v6 compatibility, but your Prisma client (likely v5) expects `Buffer`.","error":"Type 'Uint8Array' is not assignable to type 'Buffer'."}],"ecosystem":"npm"}