Type 'Array' is not generic Typescript error in generated DTO file

I’ve generated a DTO file and when I try to build the project a couple of errors are returned.

For export class GetAllConfigurations implements IReturn<Array<Configuration>> the Type 'Array' is not generic error is highlighted

For createResponse() { return new Array<Configuration>(); } the Expected 0 type arguments, but got 1 is highlighted.

TS Lint is suggesting that Array is forbidden and should be Configuration[]

What version of TypeScript are you using and is this an actual TypeScript compile error or just a TS Lint Error?

The version in package.json is “typescript”: “^3.0.1” and the error is a [ts] error which I think is a ts-loader error

Please provide the C# DTO and the generated TypeScript DTO.

C# Request class

[Route("/{OrgSlug}/configurations", Verbs = "GET")]
public class GetAllConfigurations : IReturn<Configuration[]>
{
    public string OrgSlug { get; set; }
}

TypeScript Request class

// @Route("/{OrgSlug}/configurations", "GET")
export class GetAllConfigurations implements IReturn<Array<Configuration>>
{
    orgSlug: string;
    createResponse() { return new Array<Configuration>(); }
    getTypeName() { return "GetAllConfigurations"; }
}

Array<Configuration>> is highlighted with [ts] Type 'Array' is not generic in VS Code and after doing npm run build is returned as an error.

This is the same for all the classes that have an array type in IReturn in the dtos.ts file

Should be resolved with this commit which is available from v5.1.1 that’s now available on MyGet.

Although I can’t reproduce any issue with:

createResponse() { return new Array<Configuration>(); } 

Which is valid running with TypeScript 3.0.1 or using the default TS Lint settings.

Using any combination of:

createResponse() { return new Configuration[]; } 
createResponse() { return new Configuration[]{}; } 
createResponse() { return Configuration[]; } 
createResponse() { return Configuration[]{}; } 

Results in syntax errors, the only valid syntax for returning generic arrays are:

createResponse() { return new Array<Configuration>(); } 
createResponse() { return <Configuration[]>[]; } 
createResponse() { return [] as Configuration[]; } 

I’ve chosen to retain the original syntax which uses the least foreign syntax.

Incidentally generic arrays are fairly unbalanced all-round in TypeScript as you need to use short-hand syntax when implementing a generic array argument, e.g:

public class MyRequest implements IReturm<MyArray[]> { .. }

But need to use generic type syntax if you’re extending a generic Array, e.g:

public class MyRequest extends Array<MyArray> { .. }

Thanks for the reply, will MyGet update typescript-ref as I generated the DTOs from this in VS Code

The DTO generation happens in your ServiceStack server libraries, i.e. The npm scripts that VS Code uses just calls your ServiceStack instance to generate the DTOs.

OK I’ve tried that and the DTOs are the same, what difference should I see in the generated files?

The IReturn interface marker now generates interfaces using short-hand array literal syntax, e.g IReturn<Configuration[]>.

Make sure you’re using the latest v5.1.1 on MyGet, if you were using v5.1.1 previously you will need to clear your NuGet cache, e.g:

$ nuget locals all -clear