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

type-compiler breaks on complex types #354

Closed
wielski opened this issue Aug 18, 2022 · 1 comment
Closed

type-compiler breaks on complex types #354

wielski opened this issue Aug 18, 2022 · 1 comment

Comments

@wielski
Copy link

wielski commented Aug 18, 2022

type-compiler could not serialize this kind of legit typescript types:

export type Option<T> = OptionType<T>;
class OptionType<T> {
  constructor(val: T, some: boolean) {}
}

export function Option<T>(val: T): Option<T> {
  return new OptionType(val, true);
};

const value: Option<string> = Option('hello');

In that case Option is both type alias to OptionType class, and a function that calls for new OptionType.
It compiles successfully with default tsc, but type-compiler breaks this functionality.

RangeError: Maximum call stack size exceeded
    at findVariable (deepkit-example/node_modules/@deepkit/type-compiler/dist/cjs/src/compiler.js:119:22)
    at findVariable (deepkit-example/node_modules/@deepkit/type-compiler/dist/cjs/src/compiler.js:125:16)
    at findVariable (deepkit-example/node_modules/@deepkit/type-compiler/dist/cjs/src/compiler.js:125:16)

This happens because of type-compiler loops between FunctionDeclaration and TypeReference.
One of possible solution is to add some nodes memorizing, and limit maximum depth for iterating over same nodes, as TypeScript does.

@marcj marcj closed this as completed in 7191c58 Dec 2, 2022
@marcj
Copy link
Member

marcj commented Dec 2, 2022

Thanks for the report, fixed in 7191c58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants