0

I'm using NSwag.CodeGeneration.TypeScript in a .NET 6 application to generate a file with types for the front end in TypeScript.

This is my code:

var settings = new TypeScriptClientGeneratorSettings
{
    GenerateClientClasses = false
};
settings.TypeScriptGeneratorSettings.TypeStyle = TypeScriptTypeStyle.Interface;
settings.TypeScriptGeneratorSettings.TypeScriptVersion = 3.5M;
settings.TypeScriptGeneratorSettings.DateTimeType = TypeScriptDateTimeType.String;

var generator = new TypeScriptClientGenerator(document, settings);

var code = generator.GenerateFile();

My problem is that every reference type is converted to a nullable, even if it isn't. No problems with nullable value types.

I tried using this:

settings.TypeScriptGeneratorSettings.MarkOptionalProperties = false;

But now all nullable properties (even value types) are not marked as nullables. Can I turn off marking reference types as nullables in the resulting TypeScript?

Maurice Klimek
  • 930
  • 5
  • 13
  • 48
  • When you say they are not marked as nullables, do you mean optional or nullable? `x?: number` (optional) and `x: number | null` (nullable) is not the same. – Jeppe Jul 19 '23 at 07:48
  • I consider both `| undefined` and `?: string` as a problem I'm tackling. – Maurice Klimek Jul 21 '23 at 10:32

0 Answers0