Skip to content

How use type with QueryParams #2092

Answered by Romakita
sjarrossay asked this question in Q&A
Discussion options

You must be logged in to vote

Type as now consistency in js. So typescript convert type to Object (as metadata). Prefer enum usage:

export type MyType = 'type1' | 'type2';

export class MyController {
  @Get('/')
  async tryType(@QueryParams('type') @Enum('type1', 'type2') type: MyType) {
  }
}

Better Alternative:

export enum MyEnum {
  TYPE_1 = "type1",
  TYPE_2 = "type2"
}

export class MyController {
  @Get('/')
  async tryType(@QueryParams('type') @Enum(MyEnum) type: MyEnum) {
  }
}

see you

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Romakita
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants