From 75e55c5a0466b2483d25f2c113b7a6b756365ea4 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 26 Nov 2020 20:46:18 +0000 Subject: [PATCH] fix(NJsonSchema.CodeGeneration.TypeScript): for strict null checking, include explicit '| null' to return type of createInstance (#1287) --- .../Templates/Class.liquid | 2 +- .../Templates/File.ReferenceHandling.liquid | 2 +- .../Templates/KnockoutClass.liquid | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/Templates/Class.liquid b/src/NJsonSchema.CodeGeneration.TypeScript/Templates/Class.liquid index 6ba1cf28e..46f37bd93 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/Templates/Class.liquid +++ b/src/NJsonSchema.CodeGeneration.TypeScript/Templates/Class.liquid @@ -93,7 +93,7 @@ {% endif -%} } - static fromJS(data: any{% if HandleReferences %}, _mappings?: any{% endif %}): {{ ClassName }} { + static fromJS(data: any{% if HandleReferences %}, _mappings?: any{% endif %}): {{ ClassName }}{% if HandleReferences %} | null{% endif %} { data = typeof data === 'object' ? data : {}; {% if HandleReferences -%} {% if HasBaseDiscriminator -%} diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/Templates/File.ReferenceHandling.liquid b/src/NJsonSchema.CodeGeneration.TypeScript/Templates/File.ReferenceHandling.liquid index 10d8401a7..092651124 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/Templates/File.ReferenceHandling.liquid +++ b/src/NJsonSchema.CodeGeneration.TypeScript/Templates/File.ReferenceHandling.liquid @@ -41,7 +41,7 @@ return json; } -function createInstance(data: any, mappings: any, type: any): T { +function createInstance(data: any, mappings: any, type: any): T | null { if (!mappings) mappings = []; if (!data) diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/Templates/KnockoutClass.liquid b/src/NJsonSchema.CodeGeneration.TypeScript/Templates/KnockoutClass.liquid index 360966182..8a108c6b0 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/Templates/KnockoutClass.liquid +++ b/src/NJsonSchema.CodeGeneration.TypeScript/Templates/KnockoutClass.liquid @@ -37,7 +37,7 @@ } } - static fromJS(data: any{% if HandleReferences %}, _mappings?: any{% endif %}): {{ ClassName }} { + static fromJS(data: any{% if HandleReferences %}, _mappings?: any{% endif %}): {{ ClassName }}{% if HandleReferences %} | null{% endif %} { {% if HandleReferences -%} {% if HasBaseDiscriminator -%} {% for derivedClass in DerivedClasses -%}