
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
prisma-json-types-generator
Advanced tools
Using this package? Please consider donating to support my open source work â¤ď¸
// schema.prisma
generator client {
provider = "prisma-client-js"
}
/// Always after the prisma-client-js generator
generator json {
provider = "prisma-json-types-generator"
// namespace = "PrismaJson"
// clientOutput = "<finds it automatically>"
// (./ -> relative to schema, or an importable path to require() it)
}
model Example {
/// [MyType]
normal Json
/// [MyType]
optional Json?
/// [MyType]
array Json[]
}
// index.ts
import type { Example } from '@prisma/client';
declare global {
namespace PrismaJson {
// you can use classes, interfaces, types, etc.
type MyType = boolean;
}
}
function myFunction(example: Example) {
// example.normal is now a boolean
// example.optional is now a boolean | null
// example.array is now a boolean[]
}
â ď¸ It just changes the declaration files of your generated client, no runtime code is affected!
By using the Typescript Compiler API, this generator parses the generated client's types
AST and looks for Prisma.JsonValue
types (or related) and
replaces them with their corresponding type.
There are some complex json types like JsonFilter
and JsonWithAggregatesFilter
that,
if typed, would impact the usability of the client. So, they are still json.
declare global
is not working!Using declare global
in a file that is not a module (that is contains no
import/export) is an error since everything in such a file is in the global scope anyway.
You can either remove it or add an empty export {}
to make it a module.
This project should be a temporary workaround (and possible solution) to https://github.com/prisma/prisma/issues/3219.
Json types inside type
declarations won't work. (see
https://github.com/prisma/prisma/issues/13726)
FAQs
Changes JsonValues to your custom typescript type
The npm package prisma-json-types-generator receives a total of 87,693 weekly downloads. As such, prisma-json-types-generator popularity was classified as popular.
We found that prisma-json-types-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.