Add Typescript error

Hi, I have just updated to 4.5, am using the VS extension to generate typescript ambient declarations for DTOs.

It generates the following which is illegal as QueryResponse is an interface:

// @Route("/electricity/meterReadings")
interface GetMeterReadingsRequest extends QueryDb<MeterReading>, IReturn<QueryResponse<MeterReading>>
{
    mooringId?: number;
    orderId?: number;
    deleted?: boolean;
    createResponse() { return new QueryResponse<MeterReading>(); }
    getTypeName() { return "GetMeterReadingsRequest"; }
}

If I change the ExportAsTypes to True, then the “declare” is lost from the module, which the compiler is saying is invalid.

Interface (module declaration OK but suffers from the above)

declare module dtos

Concrete (Invalid module declaration)

module dtos

Can you help?

G

Would you be able to share the AutoQuery service that generates the above?

Our techstacks.io example also users an AutoQuery endpoint but generates QueryResponse as a class.

http://techstacks.io/types/typescript

Any info on your setup to help reproduce the problem would be appreciated.

Hi, I have got around this, there are 2 problems:

a) Shouldn’t this line also check that concrete types are being generated?

I got round this by

 var nativeTypes = this.GetPlugin<NativeTypesFeature>();
  nativeTypes.MetadataTypesConfig.AddReturnMarker = false;

But, this still left the QueryDb, which will still generate the concrete “createResponse()” methods. Only way I could sort this out was to exclude all my QueryDb Types from generation.

In answer to your question, below is method that is returning a QueryResponse

   public object Get(GetMeterReadingsRequest request)
    {
        var q = AutoQuery.CreateQuery(request, Request.GetRequestParams());
        var result = AutoQuery.Execute(request, q);
        result.Results.ForEach(r =>
        {
            if (r.AccountId.HasValue) r.Account = AccountBusiness.Get(r.AccountId.Value);
            if (r.BoatId.HasValue) r.Boat = AccountBusiness.GetBoat(r.BoatId.Value);
        });
        return result;
    }

I should remove ExportAsTypes as it’s not for use in ambient type declarations ending with .d.ts. If you want to generate concrete types you should uncheck “Only TypeScript definitions” in the dialog (which is now the default):

This will generate a *.dtos.ts file instead of a .d.ts file where concrete types should no longer be wrapped in a module by default. I’ll see if I can repro the issue with AutoQuery Services with ambient type declarations.

This worked perfectly - even has the QueryDb excluded. Thanks