Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to generate class with default Date #34

Open
WilliamBlais opened this issue May 9, 2023 · 3 comments
Open

Fails to generate class with default Date #34

WilliamBlais opened this issue May 9, 2023 · 3 comments

Comments

@WilliamBlais
Copy link

WilliamBlais commented May 9, 2023

Expected Behavior

@ApiProperty({type: Date})
 metadataLastCheckedAt: Date = new Date(2000-01-01T01:00:00+00:00);

Actual Behavior

SyntaxError: ';' expected. (16:42)
  14 | 
  15 |  @ApiProperty({type: Date})
> 16 |  metadataLastCheckedAt: Date = 2000-01-01T01:00:00+00:00
     |                                          ^

Steps to Reproduce the Problem

  1. Create a Prisma schema with a default date, for example
model App {
  id        Int       @id @default(autoincrement())
  metadataLastCheckedAt        DateTime              @default("2000-01-01T01:00:00.00Z")
}
  1. Run prisma generate
  2. See error

Specifications

  • Version: 0.2.6
  • Prisma Version: 4.14.0
  • Platform: ARM
@FilipEIG
Copy link

FilipEIG commented Feb 6, 2024

This PR does not contain check whether type is DateTime:

if (this.default) {
			if (!isNaN(Date.parse(this.default))) {
				defaultValue = `= new Date('${this.default}')`

As this happens, defaults such as key Int @default(1) get outputted as key:number = new Date("1")

@longdhit
Copy link

i also got error when generate with key String @default("1")

@dengsong666
Copy link

dengsong666 commented Oct 19, 2024

The default value of the string is also problematic, I think if !isNaN(Date.parse(this.default)) should be type === 'Date'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants