@polyprism/ts-type
v0.3.1
Published
Prisma 6 & 7 generator that emits TypeScript type aliases (`export type User = { ... }`) from your schema. Pure ESM, zero runtime deps, configurable naming + annotations. Part of PolyPrism.
Maintainers
Readme
@polyprism/ts-type
A Prisma 6 & 7 generator that emits TypeScript type aliases from your schema.prisma. Part of PolyPrism.
export type User = {
id: string;
email: string;
name: string | null;
role: Role;
};Pure ESM, Prisma 7-native, zero third-party runtime dependencies. CI tests against both Prisma 6 and Prisma 7. The generated code imports nothing from PolyPrism itself — drop the generator and your output keeps compiling.
Install
pnpm add -D prisma @polyprism/ts-typeConfigure
generator polyprismCodegen {
provider = "polyprism-ts-type"
output = "../generated"
}⚠️ The provider string is the bin name (no
@scope/prefix).
Run
pnpm prisma generateOutput
// generated/User.ts
import type { Role } from "./enums/Role.js";
export type User = {
id: string;
email: string;
name: string | null;
role: Role;
};Every enum is also emitted as its own standalone ESM file at <output>/enums/<EnumName>.ts, so you can Object.values(MyEnum) directly without re-exporting through @prisma/client (whose CJS shape doesn't always play nicely with ESM consumers).
When to pick this over ts-interface
type and interface are nearly identical in TypeScript, but they diverge in a few places:
typealiases can union with other types directly (type T = User | Admin).typealiases compose into intersection (type T = A & B) and conditional types more ergonomically.interfaceis open to declaration merging;typeis closed — which some teams prefer as a "no surprises" property.- Some teams just prefer one for stylistic consistency.
If you don't have a strong preference, @polyprism/ts-interface is the more conventional pick.
What you get out of the box
- Prisma 6 & 7 compatibility — same generator binary, both Prisma majors. CI tests against both, including the Prisma 7
prisma.config.tslayout. - Pure ESM from day one — not retrofitted from a CJS codebase. No
require(), no.cjsre-export shims, no surprise. - Zero third-party runtime dependencies. This package depends only on
@polyprism/coreand@polyprism/ts-shared, neither of which has a third-party runtime dep. - Eight
///annotations —@hide,@deprecated,@json(four forms),@type,@name,@normalise,@coerce,@noCoerce. Plusprisma-json-types-generatorshorthand compatibility (/// [TypeName]). - Three-axis naming config — independently control file, type, and field naming (
snake_case,kebab-case,PascalCase,camelCase, orpreserve). - Per-identifier
@name(NewName)override — escape hatch for the global naming rule. @db.X(p, s)precision captured as JSDoc so the schema-level info survives codegen.- Optional barrel (
emitIndex = true). - Pretty-formatted inline JSON types — multi-property objects from
@json({ ... })get broken onto multiple lines instead of collapsed onto one.
Config options + annotations
Identical across all ts-* patterns — see the root README for the full config reference and annotation grammar.
Sibling patterns
Same schema, different output shape — just swap the provider:
@polyprism/ts-interface—export interface User { ... }@polyprism/ts-class—export class User { ... }with real initializer expressions@polyprism/ts-domain-class— opinionated domain class with getters/setters,@normalise/@coercedata laundering,from(),toJSON(), and a fluent builder
More patterns on the roadmap: Zod, Valibot, ArkType, TypeBox.
License
MIT © Travis Fitzgerald
