Skip to content

Generating with TS option "exactOptionalPropertyTypes" leads to errors in enums #247

@EnzoPV25

Description

@EnzoPV25

Hi,

I'm currently using this lib which is really helpfull, however I am facing a problem.

When generating with this generator :

generator nestgraphql {
  provider             = "node node_modules/prisma-nestjs-graphql"
  output               = "../src/@generated"
  reExport             = Directories
  combineScalarFilters = true
}

The generated enums are wrong because of the description field :

import { registerEnumType } from '@nestjs/graphql';

export enum ManufacturerUserRole {
    USER = "USER",
    MANAGER = "MANAGER"
}


registerEnumType(ManufacturerUserRole, { name: 'ManufacturerUserRole', description: undefined })

Here we got a TS error :

Argument of type '{ name: string; description: undefined; }' is not assignable to parameter of type 'EnumOptions<typeof ManufacturerUserRole>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'description' are incompatible.
    Type 'undefined' is not assignable to type 'string'.ts(2379)

A workaround is to modify each file with a script after generating, but I guess this is not the best way to workaround, and this should be fixed in the generated files directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions