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

"RangeError: Maximum call stack size exceeded" for intersection of recursive type #599

Closed
yang opened this issue Apr 21, 2023 · 6 comments
Closed
Assignees
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested wontfix This will not be worked on

Comments

@yang
Copy link

yang commented Apr 21, 2023

SDK Version: 2.1.0-dev.20220505

Get RangeError: Maximum call stack size exceeded with:

/** @format */

import { createIs } from "typia";

type Element =
  /** Shorthand for Text */
  | string
  | {
      component: string;
      props: Record<string, Element> & { children?: Element[] };
    };

export const check = createIs<Element>();
@samchon samchon added invalid This doesn't seem right wontfix This will not be worked on labels Apr 24, 2023
@samchon samchon self-assigned this Apr 24, 2023
@samchon samchon added bug Something isn't working invalid This doesn't seem right wontfix This will not be worked on documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested and removed invalid This doesn't seem right wontfix This will not be worked on bug Something isn't working labels Apr 24, 2023
@samchon
Copy link
Owner

samchon commented Apr 24, 2023

image

Type 'string[]' is not assignable to type 'IElement | undefined'.ts(2322)

599.ts(5, 18): The expected type comes from property 'children' which is declared here on type '{ [x: string]: IElement | undefined; }'

Tested your type with sensible expression, but TypeScript can't identify the children property.

I can't sure whether this is a bug that failed to identify the children property, or intended spec to prohibiting multiple dynamic property type definitions. Looking at error message from TypeScript compiler, it seems like a spec, but I need to ask it to the TypeScript compiler developers by writing an issue on the TypeScript repo.

Thanks for report @yang.


You can avoid the maximum call stack error by changing sensible type like above image, but generated type checking code may not what you want. As typia utilizes TS compiler API, and the TS compiler API can't identify multiple dynamic property type definitions, the children array type be ignored.

input => {
    const $join = typia_1.default.createIs.join;
    const $io0 = input => "string" === typeof input.component && ("object" === typeof input.props && null !== input.props && false === Array.isArray(input.props) && $io1(input.props));
    const $io1 = input => Object.keys(input).every(key => {
        const value = input[key];
        if (undefined === value)
            return true;
        if (RegExp(/(.*)/).test(key))
            return null !== value && (undefined === value || "string" === typeof value || "object" === typeof value && null !== value && $io0(value));
        return true;
    });
    return null !== input && undefined !== input && ("string" === typeof input || "object" === typeof input && null !== input && $io0(input));
}

@samchon samchon removed the bug Something isn't working label Apr 24, 2023
@samchon
Copy link
Owner

samchon commented Apr 24, 2023

Asked whether unable to using multiple dynamic property types is bug or not.

microsoft/TypeScript#53982

samchon added a commit that referenced this issue Apr 24, 2023
@samchon
Copy link
Owner

samchon commented Apr 24, 2023

@yang Below issue is what you want, but 7 years have passed, therefore seems hard to be accomplished.

microsoft/TypeScript#17867

@rojiwon123
Copy link
Contributor

rojiwon123 commented Apr 26, 2023

@samchon 같은 증상의 버그라서 새로운 이슈가 아닌 코맨트로 남기겠습니다!

저도 같은 증상을 겪지만 원인을 알 수 없고, 위와 같은 원인은 아닌 것 같습니다.
제가 겪는 증상은 현재 상태에서 nestia 관련 라이브러리나 typia를 업데이트 한 후에 발생합니다.
아래 링크는 정상적으로 swagger가 빌드되는 버전입니다. 하지만 해당 버전에서 nestia 계열 라이브러리나 typia를 최신 버전으로 업데이트하면 maximum callstack error가 발생하면서 swagger가 빌드되지 않습니다.

I am experiencing similar symptoms, but I don't think the cause is the same as mentioned above. The symptoms I am experiencing occur after updating the Nestia-related library or Typia in the current version. The link below shows a normal build of Swagger. However, if I update Nestia-related libraries or Typia to the latest version in the version, a maximum call stack error occurs, and Swagger cannot be built

https://github.com/zipzoong/zipzoong-backend/tree/user_system

command: npm run swagger

@samchon
Copy link
Owner

samchon commented Apr 26, 2023

@industriously Found the bug reason and fixed it.

Upgrade to [email protected], then it would be fixed.

samchon added a commit that referenced this issue Apr 26, 2023
Fix #599 - deprecated `ApplicationProgrammer.generate()` was wrong
@rojiwon123
Copy link
Contributor

rojiwon123 commented Apr 26, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants