You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using nested generics with mapped types, tsoa can't correctly infer the type of the nested payloads. If a layer of passing generics is removed, it will work.
Sorting
I'm submitting a ...
bug report
feature request
support request
I confirm that I
used the search to make sure that a similar issue hasn't already been submit
Expected Behavior
I would expect tsoa to follow multiple layers of nested/generic/mapped types. The interface with extra generics layer is semnatically the same as the one without, but produce different results.
Notice the precense of the PayloadMap_PayloadTypes_ in the json below
I would expect to use the TheRequestBody with the generic.
import{Body,Controller,Post,Route}from"tsoa";interfacePayload{key: string;payload: unknown;}exportinterfaceThePayloadextendsPayload{key: "theKey";payload: {thePayload: string;};}typePayloadMap<PayloadsextendsPayload[]>={[PayloadinPayloads[number]asPayload["key"]]?: Payload["payload"];};typePayloadTypes=[ThePayload];// To make this work, remove the `Payloads` generic and pass `PayloadTypes` directly// to the `PayloadMap` generic type.exportinterfaceTheRequestBody<PayloadsextendsPayload[]>{payloadData: PayloadMap<Payloads>;}
@Route("example")exportclassExampleControllerextendsController{
@Post()publicasyncmethod(
@Body()requestBody: TheRequestBody<PayloadTypes>){console.log(requestBody);}}
Current Behavior
Notice the missing of the PayloadMap_PayloadTypes_ properties.
To make it work I had to pass the PayloadTypes directly inside the TheRequestBody interface, instead of being able to pass it as a generic (as I used in the expected behaviour above).
Not sure how this works under the hood so can't provide a solutins, but it seems to me it has something to do with nesting of generics that is not being inferred properly
When using nested generics with mapped types, tsoa can't correctly infer the type of the nested payloads. If a layer of passing generics is removed, it will work.
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
I would expect tsoa to follow multiple layers of nested/generic/mapped types. The interface with extra generics layer is semnatically the same as the one without, but produce different results.
Notice the precense of the
PayloadMap_PayloadTypes_
in the json belowI would expect to use the
TheRequestBody
with the generic.Current Behavior
Notice the missing of the
PayloadMap_PayloadTypes_
properties.To make it work I had to pass the
PayloadTypes
directly inside theTheRequestBody
interface, instead of being able to pass it as a generic (as I used in the expected behaviour above).Possible Solution
Not sure how this works under the hood so can't provide a solutins, but it seems to me it has something to do with nesting of generics that is not being inferred properly
Steps to Reproduce
https://github.com/TimoGlastra/tsoa-error/tree/repro-nested-generics-mapped-types (note not main branch)
PayloadMap_PayloadTypes_
PayloadTypes
inTheRequestBody
PayloadMap_PayloadTypes_
Context (Environment)
Version of the library: 4.1.0
Version of NodeJS: 16.13.0
Detailed Description
Breaking change?
The text was updated successfully, but these errors were encountered: