Closed rojiwon123 closed 1 year ago
Use exact type instead of typeof
statement.
this is second case (위와 다른 상황)
@Get()
async findMany(
@Query('page') page?: string,
): Promise<
PaginatedResponse<IProduct.Summary> | typeof Exception.INVALID_QUERY // union type
> {
const npage = Number(page ?? 1);
if (isNaN(npage) || !typia.is<Page>({ page: npage }))
return Exception.INVALID_QUERY;
throw Error();
//return ProductUsecase.findMany(npage);
}
// in sdk file
export type Output = { readonly code: "4002"; readonly data: "유효하지 않은 query입니다."; } | PaginatedResponse<Summary>;
// "PaginatedResponse<Summary>" doesn't imported. (import없이 타입명만 그대로 작성됩니다.)
but why typeof statement is not recommend?
@industriously This is very similar to my implementation. I will learn about this because I can also have this problem. If I find a solution, I will share it with you. Your problem with my understanding is that if a "E" that can be defined as a union type is specified as only one "typeof", it will appear as a "__object".
@samchon
Your target instance of typeof statement is not exported TypeScript compiler does not know its exact name
I can understand number 1, but it's hard to understand that there's no problem when there's more than two "typeof". If we can solve the problem with the type of keyword, I think we can solve many other problems. Isn't it similar, for example, when we don't define a type with a specific name, but just specify the type as an interface?
@industriously This is very similar to my implementation. I will learn about this because I can also have this problem. If I find a solution, I will share it with you. Your problem with my understanding is that if a "E" that can be defined as a union type is specified as only one "typeof", it will appear as a "__object".
@kakasoo 카카수님 블로그보고 적용한 사항이에용 :) "E"가 하나면 __object가 되고 union이면 원하는데로 정상작동합니다.
you're right.
@samchon Well, I don't know what it means if it's not an intersection or union type yet and at the same time aliasSymbol is undefined. I'm currently learning what I can figure out through TS compiler's "aliasSymbol". If you accept the commit I revised now, you can solve the problem mentioned in this issue. Can you check if the direction I'm going in is correct?
Successfully created the correct SDK for both Union type and otherwise.
Decided to prohibit unnamed type using.
sdk doesn't generate Output type properly in specific case.
and it's really my code.