zod-prisma-types icon indicating copy to clipboard operation
zod-prisma-types copied to clipboard

[BUG] Unused `import type { Prisma } from './client` incompatible with `verbatimModuleSyntax` is being generated

Open kran6a opened this issue 5 months ago • 0 comments

Describe the bug When the index.ts is generated the start of the file looks like the following:

import { z } from 'zod';
import type { Prisma } from './client';

The second import is not only useless as the Prisma type is not used anywhere on the file but it is also incompatible with tsconfig option verbatimModuleSyntax as the ESM standard requires specifying the file extension so it should be import type { Prisma } from './client/index.js';

This makes code quality tools report an unused import and tsc to error due to verbatimModuleSyntax.

Package versions (please complete the following information):

  • zod: 3.23.8
  • prisma: 5.19.0

Additional context Generators defined on my prisma schema:

generator client {
  provider        = "prisma-client-js"
  output          = "./client"
  previewFeatures = ["relationJoins", "nativeDistinct", "omitApi", "driverAdapters", "typedSql"]
}

generator zod {
  provider                         = "zod-prisma-types"
  output                           = "./entities" // (default) the directory where generated zod schemas will be saved
  useMultipleFiles                 = false // default is false
  writeBarrelFiles                 = true // default is true
  createModelTypes                 = true // default is true
  addInputTypeValidation           = true // default is true
  validateWhereUniqueInput         = true // default is false
  createOptionalDefaultValuesTypes = true // default is false
  createRelationValuesTypes        = true // default is false
  createPartialTypes               = true // default is false

  createInputTypes         = false // default is true
  addIncludeType           = false // default is true
  addSelectType            = false // default is true
  useDefaultValidators     = false // default is true
  coerceDate               = true // default is true
  writeNullishInModelTypes = true // default is false
  prismaClientPath         = "./client"
}

This can be easily fixed by changing lines 19 and 21 at https://github.com/chrishoermann/zod-prisma-types/blob/master/packages/generator/src/functions/writeSingleFileImportStatements.ts

kran6a avatar Aug 31 '24 16:08 kran6a