Registry / database / prisma-generator-typescript-interfaces

prisma-generator-typescript-interfaces

JSON →
library3.1.0jsnpmunverified

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.

npm install prisma-generator-typescript-interfaces
INSTALL
IMPORT
SIG · PRISMA-GENERATOR-T
P
prisma-generator-typescript-interfaces
databasejavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Person
import { Person } from '../src/dto/interfaces';
const Person = require('../src/dto/interfaces');
Imports are for the *generated* TypeScript file, not the generator package itself. Path is relative to your source.
Gender
import { Gender } from '../src/dto/interfaces';
import Gender from '../src/dto/interfaces';
Enums are generated as named exports. Ensure `exportEnums` is not `false` in your config.
PersonJson
import { PersonJson } from '../src/dto/json-interfaces';
This example assumes a second generator instance configured with `output` and `modelSuffix` options.

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.

/* prisma/schema.prisma */ datasource db { provider = "postgresql" url = env("DATABASE_URL") } generator client { provider = "prisma-client-js" } generator typescriptInterfaces { provider = "prisma-generator-typescript-interfaces" output = "../src/types/interfaces.ts" prettier = true } enum Gender { Male Female Other } model User { id Int @id @default(autoincrement()) email String @unique name String? age Int gender Gender createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } // Then, from your terminal: // npm install --save-dev prisma-generator-typescript-interfaces prisma typescript // npx prisma generate // --- Example Usage in a TypeScript file (e.g., src/app.ts) --- import { User, Gender } from './types/interfaces'; // Path relative to the output const newUser: User = { id: 1, email: 'test@example.com', name: 'John Doe', age: 30, gender: Gender.Male, createdAt: new Date(), updatedAt: new Date() }; function processUser(user: User) { console.log(`Processing user: ${user.name || user.email}, Age: ${user.age}`); if (user.gender === Gender.Female) { console.log('User is female.'); } } processUser(newUser);
Debug
Known issues
breakingThe `omitRelations` and `optionalRelations` options were removed and replaced by a single `relations` option. Users must migrate their configurations.
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.
affects: >=3.0.0
breakingThe built-in `BufferObject` and `ArrayObject` types for the `bytesType` option have been removed. Attempting to use these will result in configuration errors.
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.
affects: >=3.0.0
breakingWhen `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.
fix
Upgrade your project's TypeScript version to 4.9 or newer. Alternatively, avoid using `enumType = "object"` and choose a different `enumType` setting.
affects: >=2.1.0
breakingThe 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.
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`.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Unknown generator option: 'omitRelations'.
The `omitRelations` option (and `optionalRelations`) was removed in version 3.0.0.
fix
Replace `omitRelations` or `optionalRelations` with the new `relations` option. For example, use `relations = "none"` to omit all relations, or `relations = "optional"`.
TS2304: Cannot find name 'BufferObject'.
The built-in `BufferObject` and `ArrayObject` options for `bytesType` were removed in v3.0.0.
fix
Remove `bytesType = "BufferObject"` (or `ArrayObject`) from your generator configuration. If you need this behavior, define a custom type using the `customTypes` option.
TS2304: Cannot find name 'satisfies'.
Your project's TypeScript version is older than 4.9, and the generator's `enumType = "object"` configuration uses the `satisfies` keyword.
fix
Upgrade your TypeScript dependency to version 4.9 or higher, or change the `enumType` option in your generator configuration to a different value.
Type 'Uint8Array' is not assignable to type 'Buffer'.
The default `bytesType` changed to `Uint8Array` in v2.0.0 for Prisma v6 compatibility, but your Prisma client (likely v5) expects `Buffer`.
fix
Explicitly set `bytesType = "Buffer"` in your `generator typescriptInterfaces` block in `schema.prisma` if you are using Prisma v5.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
prisma-generator-typescript-interfaces — npm install prisma-generator-typescript-interfaces · libregistry