Looking for options

I waited long time to update the servicestack version. 5.6 to 5.10.
I am also using typescript-ref for generating a dto in our vue js application.

However there are some changes, which I am looking for options to ‘revert’.

  • it seems that nullable types are now generated as public startDate: string -> public startDate?: string
  • I had an enum named Type which is now generated as string ! export enum Type -> export enum string
  • enums are now generated with their int values instead of string. Delivered = 'Delivered' -> Delivered = 0

So now I have a lot of errors/warnings in my Typescript (including Type 'undefined' is not assignable to type 'string'. for the nullable types). And of course the complete wrongly generated Type.

Is there a way to rollback this generation without rolling back the 5.10 on the server? With options defined in the dtos.ts ?

Have a look at docs for TypeScript Nullable Properties, you can customize the Property Type + whether the property should be nullable with the PropertyTypeFilter and IsPropertyOptional filters.

Hi thanks. This does not solve the issue. It changes public startDate?: string to public startDate : string | null which still gives me the same error in the code like Object is possibly 'null'. now.
Checked some other properties but could not find a hint to have it like it used to be.

Furthermore, what about the bug with enum Type?

You shouldn’t use the filter implementations (which is what happens when you use TypeScriptGenerator.UseNullableProperties=true), but PropertyTypeFilter lets you control both the Type of the property whilst IsPropertyOptional lets you control whether it’s optional.

Can you provide the actual C# DTO Types that’s causing the issues so I can see what it’s generating.

Ok, I could fix it with:

TypeScriptGenerator.IsPropertyOptional = (generator, type, prop) => false;

TypeScriptGenerator.PropertyTypeFilter = (gen, type, prop) => 
    gen.GetPropertyType(prop, out var isNullable);

That gives me back the original generated code.

For the Type issue:

public enum Type


export enum string
    Text = 'Text',
    Number = 'Number',
    Decimal = 'Decimal',
    Email = 'Email'

The Type’s name goes through the TypeFilter so they make use of the TypeAliases which you revert by removing the alias, e.g:


Ok, added this one too.

Everything back to normal :+1:

1 Like