Skip to content

How to return generic class from endpoint? #1573

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

You must be logged in to vote

@detroitpro I invite you to read the documentation about generics ;)

https://tsed.io/docs/model.html#generics

Why this notation is incorrect?

Returns(200, ApiResult<UserResponse>)

Written as it, ApiResult is considered by typescript as an interface and not to a valid parameter (so a valid javascript object after transpilation)!

The correct syntax could be:

Returns(200, ApiResult).Of(UserResponse)

But you have to add extra decorator on ApiResult to propagate the UserResponse schema on this endpoint. Look the docs to found the answers ;)

See you
Romain

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by detroitpro
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