Brakebein / prisma-generator-nestjs-dto

Generates NestJS DTO classes from Prisma Schema
Apache License 2.0
45 stars 24 forks source link

Optionally add Definite Type Assertion #14

Closed richardweaver closed 1 year ago

richardweaver commented 1 year ago

Firstly, can I say kudos for taking this library forward and your enhancements - it's so great to be able to use Prisma as the single source of truth for the model, DTOs, validation and OpenAPI.

One suggestion: fields in DTO and entity classes could (optionally) be specified with the Definite Type Assertion ! prefix. This is so that we don't need to set "strictPropertyInitialization": false in tsconfig.json.

For example, the schema:

integerField:  Int
stringField:  String

... the generated fields are:

  integerField: number;
  stringField: string;

It would be great to be able instead to output

  integerField!: number;
  stringField!: string;

Definite Type Assertion was specifically added to Typescript to account for scenarios where fields are not necessarily initialised in a constructor but populated by an external library - exactly as with a DTO. Docs

Brakebein commented 1 year ago

Good point. Should be a rather easy enhancement. Maybe I'll be able to do it this week,

Brakebein commented 1 year ago

With the latest release, you can now set the flag definiteAssignmentAssertion = "true" to add the definite assignment assertion operator ! to properties.

richardweaver commented 1 year ago

Brilliant, thanks!