lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.48k stars 498 forks source link

TypeError: Cannot read properties of undefined (reading 'kind') #1566

Closed jchantrell closed 6 months ago

jchantrell commented 7 months ago

Sorting

Expected Behavior

I am running npx tsoa routes and it's throwing with this error: There was a problem resolving type of 'MyType'. which is an interface declared by another package. It fails for all interfaces that include it as a reference. Shape of the interface and additional error info below.

export interface MyType {
    a: string;
    b: string | Array<string>;
    c: Map<string, any>;
}
There was a problem resolving type of 'MyType'.
Generate routes error.
 TypeError: Cannot read properties of undefined (reading 'kind')
    at Object.isEnumMember
...

Current Behavior

It is throwing errors any time a typescript Map<string, any> type is mentioned in an interface.

Possible Solution

I have stepped through the functions that are handling it and have determined that it's failing while parsing the Map<string, any> property of MyType. It seems that there is code that filters down types that belong to typescript which makes the Map type return with no type declarations. Those declarations are returned as an array then the first element of that array is passed into another handler that's causing this error to be thrown.

The code that is filtering down the native typescript types and returning an empty array: https://github.com/lukeautry/tsoa/blob/daadfe6279290bb9729423ac9d56b9518d70ee18/packages/cli/src/metadataGeneration/typeResolver.ts#L1214-L1221

The code where it's returned to that throws the error: https://github.com/lukeautry/tsoa/blob/daadfe6279290bb9729423ac9d56b9518d70ee18/packages/cli/src/metadataGeneration/typeResolver.ts#L696-L711

Steps to Reproduce

  1. Follow instructions in getting started tutorial up to the point where you run yarn run tsoa routes
  2. Extend the User interface from the tutorial with a Map<string, any>
  3. Run the command to generate routes
export interface User {
  id: number;
  email: string;
  name: string;
  status?: 'Happy' | 'Sad';
  phoneNumbers: string[];
  map: Map<string, any>; # add this in
}

Context (Environment)

Version of the library: 6.0.1 Version of NodeJS: 18

Detailed Description

Apologies if I am missing something obvious.

Breaking change?

nil

github-actions[bot] commented 7 months ago

Hello there jchantrell 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days