Brakebein / prisma-generator-nestjs-dto

Generates NestJS DTO classes from Prisma Schema
Apache License 2.0
43 stars 23 forks source link

connect DTO - Subsequent property declarations must have the same type. #35

Open ReptoxX opened 8 months ago

ReptoxX commented 8 months ago

On every connect DTO is an typescript error, that the field is defined twice with different types.

import { ApiExtraModels, ApiProperty } from '@nestjs/swagger';

class UserIdUniqueInputDto {
    @ApiProperty({
        default: 'cuid',
    })
    id!: string;
}

@ApiExtraModels(UserIdUniqueInputDto)
export class ConnectUserDto {
    @ApiProperty({
        required: false,
        nullable: true,
    })
    id?: string;
    @ApiProperty({
        required: false,
        nullable: true,
    })
    mail?: string;
    @ApiProperty({
        type: UserIdUniqueInputDto,
        required: false,
        nullable: true,
    })
    id?: UserIdUniqueInputDto;
}

Parameters used:

generator nestrestapi {
  provider                        = "prisma-generator-nestjs-dto"
  output                          = "../models/@generated/rest"
  definiteAssignmentAssertion     = true
  prettier                        = true
  reExport                        = true
  outputToNestJsResourceStructure = true
  exportRelationModifierClasses   = false
}
ReptoxX commented 8 months ago

The problem is i use @@id([id]) to define the id of the table. Example

model User {
  id             String     @default(cuid())
  mail           String     @unique

  @@id([id])
  @@map("users")
}

When using

model User {
  id             String     @default(cuid()) @id
  mail           String     @unique

  @@map("users")
}

the error does not occur.

Brakebein commented 7 months ago

I think it's a bug with having only one value within the array of @@id(). It is possible that unique constraint with only one value, e.g. @@unique([mail]), behaves similar. I need to check it.