lukeautry / tsoa

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

Can't call methods from @Inject class using typescript-io. #1529

Closed hs-wolf closed 7 months ago

hs-wolf commented 7 months ago

Hi, I have a very simple project setup, with Nx as mono repo solution and a barebones Express app.

The app has 1 controller and 1 service, I tried following Tsoa's official guide on how to implement typescript-ioc: https://tsoa-community.github.io/docs/di.html#typescript-ioc

Even though the routes and app are being built, and the app is being served correctly, I get an error when calling methods from an injected class.

Sorting

Expected Behavior

I should be able to call methods from a class using the @Inject decorator.

My base tsconfig.ts file has the decorator properties set.

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
  }
}

Current Behavior

When calling a method from a class using the @Inject decorator I get the error bellow. It's not very informative and I couldn't find a similar error that matched my case.

TypeError: Invalid type requested to IoC container. Type is not defined.

Possible Solution

Maybe a configuration or package/package version that I'm missing?

Steps to Reproduce

  1. Clone repo.
    git clone --single-branch --branch template-name https://github.com/hs-wolf/nx-monorepo-templates.git
  2. Install pnpm
    npm install -g pnpm
  3. Install packages
    pnpm install
  4. Run Express App
    npx nx run express-api:serve:development
  5. Open http://localhost:3000/docs/
  6. Find the users/{userId} endpoint, open It and try any number as the Id to call the service.
  7. Back to VSCode terminal to see the error.

Context (Environment)

Version of the library:

"@tsoa/runtime": "^5.0.0" "tsoa": "^5.1.1"

Version of NodeJS: v18.19.0

github-actions[bot] commented 7 months ago

Hello there hs-wolf 👋

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

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