Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling parameters that include mapped types with Date as a generic argument #1731

Open
2 of 4 tasks
veiper93 opened this issue Dec 18, 2024 · 0 comments
Open
2 of 4 tasks

Comments

@veiper93
Copy link

This is reopening of an issue #1596, which also got the potential fix #1597 which never got merged.

An error is raised by invoking npx tsoa spec-and-routes when one of the endpoints within routers has a @Body() parameter that includes a mapped type field with Date as a generic argument. The error is introduced with the tsoa 6.0.0 version. It was not present up until and including the tsoa 5.1.1 version.

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

The following TypeScript code should be processed by tsoa spec-and-routes without any issue.

import { Body, Controller, Post, Route, Tags } from "tsoa";

interface Mapped<T> {
  array: T[];
}

interface DummyBody {
  field: DummyBodyField;
}

interface DummyBodyField {
  date: Mapped<Date>; // !!! date causes problem !!!
  string: Mapped<string>; // string is ok
  number: Mapped<number>; // number is ok
  boolean: Mapped<boolean>; // boolean is ok
}

@Route("dummy")
export class DummyController extends Controller {
  @Post()
  async dummy(@Body() dummyBody: DummyBody): Promise<void> {
    console.log(dummyBody);
  }
}

Current Behavior

For a TypeScript code in the Expected Behavior section, primitive types string, number, and boolean do not cause the error. I also think that custom simple JavaScript classes do not cause the error. Standard JavaScript Date type, on the other hand, seems to be causing an error.

The following error is returned by tsoa spec-and-routes.

There was a problem resolving type of 'DummyBodyField'.
There was a problem resolving type of 'DummyBody'.
Generate routes error.
 GenerateMetadataError: Cannot read properties of undefined (reading 'kind') 
 in 'DummyController.dummy'
    at /workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:104:23
    at Array.map (<anonymous>)
    at MethodGenerator.buildParameters (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:96:14)
    at MethodGenerator.Generate (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:66:33)
    at /workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:41
    at Array.map (<anonymous>)
    at ControllerGenerator.buildMethods (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:14)
    at ControllerGenerator.Generate (/workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:35:27)
    at /workspaces/workspace/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:210:41
    at Array.map (<anonymous>)

Steps to Reproduce

The bug should be easily reproducible using the code supplied in the Expected Behavior section.

There is also a devbox on codesandbox.io.

Context (Environment)

In addition to the devbox where yarn was used, the error persist on the local machine where npm was used.

Version of the library: 6.6.0
Version of NodeJS: v20.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant