From 4a64232d613eabe424999a6196e0c3a2244de2bb Mon Sep 17 00:00:00 2001 From: Honza Jerabek Date: Sun, 9 Jan 2022 10:27:08 +0100 Subject: [PATCH] Allow optional fields to be null --- src/auto-generator.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/auto-generator.ts b/src/auto-generator.ts index 9d3b4252..95ce2ccb 100644 --- a/src/auto-generator.ts +++ b/src/auto-generator.ts @@ -698,7 +698,13 @@ export class AutoGenerator { if (!this.options.skipFields || !this.options.skipFields.includes(field)){ const name = this.quoteName(recase(this.options.caseProp, field)); const isOptional = this.getTypeScriptFieldOptional(table, field); - str += `${sp}${name}${isOptional ? '?' : notNull}: ${this.getTypeScriptType(table, field)};\n`; + str += `${sp}${name}${isOptional ? '?' : notNull}: ${this.getTypeScriptType(table, field)}`; + + if (isOptional) { + str += ' | null' + } + + str += ';\n' } }); return str;