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

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

Closed
2 of 4 tasks
jchantrell opened this issue Feb 18, 2024 · 2 comments
Closed
2 of 4 tasks

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

jchantrell opened this issue Feb 18, 2024 · 2 comments
Labels

Comments

@jchantrell
Copy link

jchantrell commented Feb 18, 2024

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 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:

if (modelTypes.length > 1) {
// remove types that are from typescript e.g. 'Account'
modelTypes = modelTypes.filter(modelType => {
return modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules/typescript') <= -1;
});
modelTypes = this.getDesignatedModels(modelTypes, typeName);
}

The code where it's returned to that throws the error:

const declarations = this.getModelTypeDeclarations(type);
//Two possible solutions for recognizing different types:
// - Add declaration positions into type names (In an order).
// - It accepts multiple types with same name, if the code compiles, there would be no conflicts in the type names
// - Clear namespaces from type names.
// - Horrible changes can be in the routes.ts in case of teamwork,
// because source files have paths in the computer where data generation runs.
// - Use fully namespaced names
// - Conflicts can be recognized because of the declarations
//
// The second was implemented, it not changes the usual type name formats.
const oneDeclaration = declarations[0]; //Every declarations should be in the same namespace hierarchy
const identifiers = name.split('.');
if (ts.isEnumMember(oneDeclaration)) {

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

  • Confirm you were using yarn not npm: [x]

Detailed Description

Apologies if I am missing something obvious.

Breaking change?

nil

Copy link

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.👀

Copy link

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

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

No branches or pull requests

1 participant