Search code examples
typescriptinterfacecontrollernestjsdto

UpdateController gives error about PartialTypeDTO conflicting with Interface used in Service


CreateAdmin.DTO.ts enter image description here

UpdateAdmin.DTO.ts

Which is inherited by PartialTypes so the values whilst updating the admin are optional for all fields.

enter image description here

AdminInterface.ts

enter image description here

admin.controller.ts

This is my update controller, I want to use the PartialTypes without having to create a second interface for this(I don't know why, That seems wrong to use 2 interfaces).

enter image description here

This is the error that is being displayed on VSCODE.

enter image description here

I tried making a second interface but that seemed wrong as mentioned earlier.

So the solution right now, What I can see is to make a new interface for the Update(Patch/PUT) endpoints.

Admin.Service.ts enter image description here


Solution

  • The Typescript error is clear. All of your UpdateAdminDTO properties are marked as optional, whilst your Admin interface expected in the updateAdmin method for your AdminService does not allow optional properties.

    If you're leaned towards a more DDD-ish design, you will have to map your UpdateAdminDTO data to your Admin interface.