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

fix: <Injected Response object is undefined> #1206

Open
schongabor opened this issue Aug 18, 2023 · 1 comment
Open

fix: <Injected Response object is undefined> #1206

schongabor opened this issue Aug 18, 2023 · 1 comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@schongabor
Copy link

Description

After upgrading from 9.0.0 to the latest version the objects injected by decorators to controllers are undefined.

import { Response } from 'koa';
import 'reflect-metadata';
import { Get, JsonController, Res } from 'routing-controllers';
import { autoInjectable } from 'tsyringe';

import { Controller } from '../interface';
import { StatusCodes } from 'http-status-codes';

@JsonController('/example')
@autoInjectable()
export class ExampleController implements Controller {
  constructor() {
  }

  @Get()
  async process(@Res() response: Response) {
    console.log('inside controller');     // this is logged ✅
    console.log(response);                   // this is undefined ❌

    response.status = StatusCodes.OK
    response.body = { some: 'response' }

    return response;
  }
}

Expected behavior

Should return the response object

Actual behavior

{
    "name": "TypeError",
    "message": "Cannot set properties of undefined (setting 'status')",
    "stack": "TypeError: Cannot set properties of undefined (setting 'status')\n.....
}
@schongabor schongabor added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Aug 18, 2023
@attilaorosz
Copy link
Member

It took me a good while to try to debug this. Unfortunately tsyringe is the issue here. If you remove @autoInjectable() and replace it with typedi for example, it works fine. Seems like @autoInjectable alters the class somehow and the param resolution is not working because the registered class is different from the actual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

2 participants