Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too long return type fails to generate SDK #282

Closed
kakasoo opened this issue Mar 16, 2023 · 3 comments
Closed

Too long return type fails to generate SDK #282

kakasoo opened this issue Mar 16, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@kakasoo
Copy link
Contributor

kakasoo commented Mar 16, 2023

Hello, I brought a new issue today. :(

Now I have implemented a type called Try<T,E>. I defined a type that returns T in normal cases and E in other cases. I decided to treat errors as an object instead of throwing it so that even all errors could be inferred.
Therefore, this type of Try<T,E> is deduced to be a very long return type.

The problem happened here.
If you look at the code below, you can immediately see how Nestia generated the SDK.

  @TypedRoute.Get('omg')
  async ThisFunctionHasTooLongReturnType(): Promise<
    Try<
      true,
      | typeof ERROR.TOO_LONG_KEY_NAME1
      | typeof ERROR.TOO_LONG_KEY_NAME2
      | typeof ERROR.TOO_LONG_KEY_NAME3
      | typeof ERROR.TOO_LONG_KEY_NAME4
      | typeof ERROR.TOO_LONG_KEY_NAME5
    >
  > {
    /**
     * If it's not zero, then return ERROR object.
     */
    let something: number = 0;
    if (something === 0) {
      return { result: true, code: 1000, data: true };
    } else if (something === 1) {
      return ERROR.TOO_LONG_KEY_NAME1;
    } else if (something === 2) {
      return ERROR.TOO_LONG_KEY_NAME2;
    } else if (something === 3) {
      return ERROR.TOO_LONG_KEY_NAME3;
    } else if (something === 4) {
      return ERROR.TOO_LONG_KEY_NAME4;
    } else if (something === 5) {
      return ERROR.TOO_LONG_KEY_NAME5;
    }
  }
export namespace ThisFunctionHasTooLongReturnType
{
    export type Output = Primitive<Try<true, { readonly result: false; readonly code: 4000; readonly data: "Error happens something1."; } | { readonly result: false; readonly code: 4000; readonly data: "Error happens something2."; } | { ...; } | { ...; } | { ...; }>>;

    export const METHOD = "GET" as const;
    export const PATH: string = "/omg";
    export const ENCRYPTED: Fetcher.IEncrypted = {
        request: false,
        response: false,
    };

    export function path(): string
    {
        return `/omg`;
    }
}

Please check the Output type of the namespace "ThisFunctionHasTooLongReturnType".
At the end of the type, "{...; } | {...; } | { ...; }".

if you check this...

git clone https://github.com/kakasoo/nestia-demo
cd nestia-demo
git switch nestia#28x
npm i
npm run build

Then, you can check this bug. ( src/api/functional/api/omg/index.ts)

samchon added a commit to samchon/typia that referenced this issue Mar 16, 2023
samchon added a commit that referenced this issue Mar 16, 2023
@samchon
Copy link
Owner

samchon commented Mar 16, 2023

Upgrade packages, then no problem would be:

  • typia: 3.6.8
  • @nestia/core: 1.0.17
  • @nestia/sdk: 1.0.16

@samchon samchon self-assigned this Mar 16, 2023
@samchon samchon added the bug Something isn't working label Mar 16, 2023
samchon added a commit that referenced this issue Mar 16, 2023
@kakasoo
Copy link
Contributor Author

kakasoo commented Mar 18, 2023

git clone https://github.com/kakasoo/nestia-demo
cd nestia-demo
git switch nestia#28x
npm i
npm run build

I updated it to the version as you specified and then created the SDK again. But nothing has changed.
Please check one more.

23.03.19
I leave an additional comment because I am not authorized to reopen this issue. Currently, this issue is not resolved, but it will be resolved once that PR is passed.

@kakasoo
Copy link
Contributor Author

kakasoo commented Mar 18, 2023

@samchon
I mention you because it is a closed issue.

kakasoo added a commit to kakasoo/nestia that referenced this issue Mar 19, 2023
- ts.TypeFormatFlags.NoTruncation apply
- I don't know how to test it work correctly, so I need your help.
samchon added a commit that referenced this issue Mar 27, 2023
fix : Too long return type fails to generate SDK #282
samchon added a commit that referenced this issue Mar 27, 2023
samchon added a commit that referenced this issue Mar 27, 2023
Fix #282 and Complement #284 - full name typing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants