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]: RangeError: Maximum call stack size exceeded at isExtendable #495

Closed
alpharder opened this issue Oct 27, 2023 · 11 comments
Closed

Comments

@alpharder
Copy link
Contributor

Problematic code:

import { ObjectTypeDefinitionJsonMetaSchema } from '../../domain/object-types/object-type-definition-json-meta-schema.domain-model.js';

export interface IObjectTypesJsonMetaSchemasProvider {
  getObjectTypeDefinitionJsonMetaSchema():
    | Promise<ObjectTypeDefinitionJsonMetaSchema>
    | ObjectTypeDefinitionJsonMetaSchema;
}

Error:

file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:49
export function isExtendable(leftValue, rightValue, extendStack = []) {
                            ^

RangeError: Maximum call stack size exceeded
    at isExtendable (file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:49:29)
    at file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:287:55
    at Array.every (<anonymous>)
    at isExtendable (file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:287:31)
    at file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:287:55
    at Array.every (<anonymous>)
    at isExtendable (file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:287:31)
    at isExtendable (file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:279:31)
    at isFunctionParameterExtendable (file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:368:19)
    at isExtendable (file:///Users/alpharder/dev/personal/deepkit-framework/packages/type/dist/esm/src/reflection/extends.js:187:24)

Node.js v21.1.0

Changing signature to this causes error to disappear:

import { ObjectTypeDefinitionJsonMetaSchema } from '../../domain/object-types/object-type-definition-json-meta-schema.domain-model.js';

export interface IObjectTypesJsonMetaSchemasProvider {
  getObjectTypeDefinitionJsonMetaSchema(): ObjectTypeDefinitionJsonMetaSchema;
}
@alpharder
Copy link
Contributor Author

I saw similar reports (#478 , #477).

@marcj Assuming this is the same issue. I saw your comment about potentially required fundamental changes in the VM: #478 (comment)

We could avoid that, at least as a temporary solution.
I'm not sure whether this is actually an infinite recursion.
If this is finite, we could rewrite recursive functions to manage their own stack instead.

@marcj
Copy link
Member

marcj commented Oct 27, 2023

whats the type of ObjectTypeDefinitionJsonMetaSchema?

@alpharder
Copy link
Contributor Author

export type ObjectTypeDefinitionJsonMetaSchema = {
  foo: 'bar';
};

@alpharder
Copy link
Contributor Author

export type ObjectTypeDefinitionJsonMetaSchema = {
  foo: string;
};

also doesn't work

@marcj
Copy link
Member

marcj commented Oct 27, 2023

that's the type that breaks? so simple? then definitely a bug

@alpharder
Copy link
Contributor Author

Yes, it's exactly the type I had, very basic.

@marcj
Copy link
Member

marcj commented Oct 27, 2023

Need more information since this is not replicable. What are you doing with IObjectTypesJsonMetaSchemasProvider?

@alpharder
Copy link
Contributor Author

You may find environment it's reproducible in at #496, that's another problem but similar code.

@timvandam
Copy link
Contributor

I saw similar reports (#478 , #477).

@marcj Assuming this is the same issue. I saw your comment about potentially required fundamental changes in the VM: #478 (comment)

We could avoid that, at least as a temporary solution. I'm not sure whether this is actually an infinite recursion. If this is finite, we could rewrite recursive functions to manage their own stack instead.

I don't think #477 is related, as its a V8 OOM instead of a Stack Overflow error

@marcj
Copy link
Member

marcj commented Oct 27, 2023

@alpharder Ok I've managed to replicate it

    type ObjectTypeDefinitionJsonMetaSchema = {
        foo: string;
    };

    type IObjectTypeJsonMetaSchemasProvider = {
        getObjectTypeDefinitionJsonMetaSchema(): Promise<ObjectTypeDefinitionJsonMetaSchema> | ObjectTypeDefinitionJsonMetaSchema;
    };

    class CmsService {
        async getObjectTypeDefinitionJsonMetaSchema(): Promise<ObjectTypeDefinitionJsonMetaSchema> {
            return {foo: 'bar'};
        }
    }

    type T = CmsService extends IObjectTypeJsonMetaSchemasProvider ? true : false;
    const type = typeOf<T>();

@marcj marcj closed this as completed in aa66460 Oct 27, 2023
@marcj
Copy link
Member

marcj commented Oct 27, 2023

@alpharder fixed in aa66460

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

3 participants