2

When adding a TypeScript Reference using ServiceStackVS, the resulting .d.ts file generates an error, "Cannot find name 'Nullable'.", for any Request DTO properties that are arrays. For example, I have a Request DTO for finding Events:

public class FindEvents : QueryBase<Event> {
    ...

    [QueryField(Template = "{Field} BETWEEN {Value1} AND {Value2}", Field = "StartDateTime")]
    public DateTime?[] DateBetween { get; set; }

    [QueryField(Template = "MONTH({Field}) BETWEEN {Value1} AND {Value2}", Field = "StartDateTime")]
    public int?[] MonthBetween { get; set; }

    ...
}

The generated interface for this Request DTO looks like:

interface FindEvents extends QueryBase_1<Event>, IReturn<QueryResponse<Event>>
{
    ...

    DateBetween?: Nullable;
    MonthBetween?: Nullable;
    ...

}

The generated type "Nullable" is what's causing the error.

In the service, I can change DateTime?[] and int?[] to string[] and that will generate DateBetween?: string[]; and MonthBetween?: string[]; respectively.

That will work - in the service and in the TypeScript code - but I would prefer not to change the service in that way.

Any suggestions? Can ServiceStackVS be updated to handle Request DTO properties that are arrays?

Thanks.

1 Answer 1

3

Arrays are already nullable reference types in .NET so you don't need to specify it contains nullable value types as well.

AutoQuery also doesn't handle arrays where some of the ValueTypes are null, so you should just change the arrays to non-nullable Value Types, e.g:

public class FindEvents : QueryBase<Event> 
{
    [QueryField(Template = "{Field} BETWEEN {Value1} AND {Value2}", Field = "StartDateTime")]
    public DateTime[] DateBetween { get; set; }

    [QueryField(Template = "MONTH({Field}) BETWEEN {Value1} AND {Value2}", Field = "StartDateTime")]
    public int[] MonthBetween { get; set; }
}

This ends up providing a nicer strong-typed API whilst the properties remain optional.

Note: DateTime's are emitted as strings in TypeScript to match how they're sent in JSON.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Demis - great as always!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.