The generator supports two ways to define types for Prisma fields:
1. Namespace-based Types (/// [TypeName])
Use this for reusable or complex shapes, large JSON payloads, or types that will be validated with libraries like Zod. This requires defining the type within a PrismaJson namespace in a TypeScript declaration file.
Prisma Schema:
model User {
/// [UserProfile]
profile Json
}
TypeScript Declaration:
import type { UserProfile as DomainUserProfile } from './domain/user-profile';
declare global {
namespace PrismaJson {
type UserProfile = DomainUserProfile;
}
}
2. Inline Types (/// ![TypeExpression])
Use this for shorter, simpler types or literal unions. The full TypeScript type expression is written directly in the comment.
Prisma Schema:
model Post {
/// !['draft' | 'published' | 'archived']
status String
/// ![1 | 2 | 3]
rank Int
/// ![{ theme: 'dark' | 'light'; twitterHandle?: string }]
profile Json
}
model User {
/// [UserProfile]
profile Json
}
import type { UserProfile as DomainUserProfile } from './domain/user-profile';
declare global {
namespace PrismaJson {
type UserProfile = DomainUserProfile;
}
}
model Post {
/// !['draft' | 'published' | 'archived']
status String
/// ![1 | 2 | 3]
rank Int
/// ![{ theme: 'dark' | 'light'; twitterHandle?: string }]
profile Json
}