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: TypeError: Cannot read properties of undefined (reading 'prototype') #924

Open
anishjneoito opened this issue Nov 3, 2022 · 4 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@anishjneoito
Copy link

anishjneoito commented Nov 3, 2022

I'm getting the following error after building the app. I'm getting only when i pass query param.
/api/role is working fine. But /api/role?type=1 is throwing below error

" TypeError: Cannot read properties of undefined (reading 'prototype') at ActionParameterHandler.normalizeParamValue)

My code is below. I've emitDecoratorMetadata": true in tsconfig compilerOptions as well.
@Get('/role')
async getRole(@QueryParams() query: any) {
console.log(query.type)
}
Did I miss anything?

@anishjneoito anishjneoito added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Nov 3, 2022
@spicemc
Copy link

spicemc commented Nov 7, 2022

I think instead of using the type any it should be something like:
async getRole(@QueryParams() query: RolesQuery) {

Create a class RolesQuery.

A good example in the documentation is the class GetUsersQuery: QueryParams Example

@thebinij
Copy link

thebinij commented Dec 2, 2022

// ActivityController.ts
...

@Get("/activities")
    public async getPaginated(
      @CurrentUser({ required: true }) uid: string,
      @QueryParams() query: ActivityParams
...

// ActivityModel.ts

export class ActivityParams{
  @IsPositive()
  limit:number;

  @IsPositive()
  startAt:number
}

I am also getting same error even after following the docs.
TypeError: Cannot read properties of undefined (reading 'prototype')

Can anyone help ?

@attilaorosz
Copy link
Member

attilaorosz commented Dec 3, 2022

It’s a bit hard to diagnose without the full context. Did you import reflect-metadata? Are you using koa or express?

@jrthib
Copy link

jrthib commented Aug 19, 2023

Adding import "reflect-metadata"; at the top of your controller seems to fix this. I was experiencing the same issue. Was consistently reproducible when using @QueryParams(). So you can either switch to @QueryParam as a workaround, which doesn't throw this error, or you can import reflect-metadata at the top of your controller file and it'll be fixed.

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

5 participants