kimjbstar / prisma-class-generator

Class generator from Prisma schema.
175 stars 50 forks source link

class generate with "Declarations with initializers cannot also have definite assignment assertions." error #56

Open x-etienne opened 10 months ago

x-etienne commented 10 months ago

Expected Behavior

Generate the class without annoying error "Declarations with initializers cannot also have definite assignment assertions." and for number type generate a default value as Date.

Actual Behavior

Actualy when I generate a class, when a property in the schema has a default value, the generator create a class with error

Steps to Reproduce the Problem

With this schema

generator client {
  provider = "prisma-client-js"
  output   = env("PRISMA_CLIENT_PATH")
}

generator prismaClassGenerator {
  provider                 = "prisma-class-generator"
  dryRun                   = false
  useSwagger               = false
  makeIndexFile            = false
  separateRelationFields   = false
  useNonNullableAssertions = true
  output                   = "./models"
}

datasource db {
  provider = "sqlite"
  url      = env("PRISMA_DATABASE_URL")
}

model test{
  id                 String  @id
  description  String? 
  value            Int    @default(1)
} 

The generator create this class

export class item {
  id!: string;   // here for me is correct

  description?: string; 

  value!: number = new Date('1');;  // <- this is the problem, the ! and type of value (Date instead of number)

}

Specifications

woodenfish commented 3 months ago

Same issue