samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.85k stars 95 forks source link

`TypedRoute` named property on implicit return typed got removed #356

Closed mlazuardy closed 1 year ago

mlazuardy commented 1 year ago

When return an implicit response of Post method using named property, the named property got removed

Minimum reproduce repository can be found here

https://github.com/mlazuardy/nestjs-starter

as you can see here in TokenController https://github.com/mlazuardy/nestjs-starter/blob/main/src/user/token.controller.ts

import { $string } from "@/common/utils/string";
import { TypedRoute } from "@nestia/core";
import { Controller } from "@nestjs/common";
import { JwtService } from "@nestjs/jwt";

@Controller("tokens")
export class TokenController {
  constructor(private jwtService: JwtService) {}

  @TypedRoute.Post()
  async create() {
    const accessToken = this.jwtService.sign({
      sub: 1,
    });

    const randomString = $string().random(100);

    return { accessToken, randomString: randomString };
  }
}

as you can see accessToken used named property inside return and it got removed on the response. while the randomString is fine by duplicating the property named as key

im not really sure if nestia/typia required an explicit return for the response since duplicating or defining key is fine

I really like the project and maybe I might help you later

samchon commented 1 year ago

Define exact return type.

I will prohibit implicit return type ar next major patch.

The next major patch would come with TS 5.2 release.