Closed kakasoo closed 1 year ago
I thought about it after writing the question, but it seems that it can be solved by using the internal type of Observable<ExtendedResponse
Is it difficult to consider the case of returning the generic T of the intercept method in a different form?
Show me demonstration project occuring the type inference error
I was a little late writing the example code. Feel free to answer slowly. I'm going to go to bed now. :) There are two problems here.
git clone https://github.com/kakasoo/nestia-demo
cd nestia-demo
git switch nestia#279
npm i
npm run build
npm run test:watch
Ah, understood what you want, and it is not possible through nestia
.
Such type transformation can't be detected in the compilation level.
OK, I see. I have now implemented separate utility types and functions to solve this problem on the controller. Even if your answer doesn't solve my problem, I fully understand it and still love this project. Thank you.
https://docs.nestjs.com/interceptors#response-mapping
This code is an interceptor in the nest.js official document. When transforming with an interceptor, the SDK in nestia deduces a different type from the actual response.
I'm actually using an interceptor for transform in my code. 1) The logic is to assign additional properties to the response type and 2) If controller's return type have the properties named
list
andcount
, the server should consider it a pagination and assign additional properties such astotalCount
andtotalPage
. All I'm saying is, I want to hear your thoughts on what to do if you format the response form in the interceptor.I didn't have an idea to solve this, so I defined a separate pagination function and various utility types to help it, and I removed transform.interceptor. But I'm thinking about whether there was really no other way.