Infinite loop when resolving type args #4

Closed
opened 2025-03-17 18:35:35 +01:00 by unconed · 1 comment
unconed commented 2025-03-17 18:35:35 +01:00 (Migrated from github.com)

While trying to ingest React types with getdocs-ts, ReactElement causes an infinite loop. It's recursive in its own type parameters, via JSXElementConstructor:

    interface ReactElement<P = any, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
        type: T;
        props: P;
        key: Key | null;
    }

    type JSXElementConstructor<P> =
        | ((props: P) => ReactElement<any, any> | null)
        | (new (props: P) => Component<any, any>);

This appears to cause an infinite loop as getReferenceType tries to build the type args:

        let args = typeArgs.map(arg => this.getType(arg))

This isn't a huge problem as I don't need to document this type (I skipped it as a workaround), but I figured it was worth reporting. It would've also been easier to chase down if getdocs had a trace mode so it could print the names of the files and symbols it's trying to resolve, as "maximum call stack exceeded" is a pain to trap.

While trying to ingest React types with getdocs-ts, `ReactElement` causes an infinite loop. It's recursive in its own type parameters, via `JSXElementConstructor`: ``` interface ReactElement<P = any, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> { type: T; props: P; key: Key | null; } type JSXElementConstructor<P> = | ((props: P) => ReactElement<any, any> | null) | (new (props: P) => Component<any, any>); ``` This appears to cause an infinite loop as `getReferenceType` tries to build the type args: ``` let args = typeArgs.map(arg => this.getType(arg)) ``` This isn't a huge problem as I don't need to document this type (I skipped it as a workaround), but I figured it was worth reporting. It would've also been easier to chase down if getdocs had a trace mode so it could print the names of the files and symbols it's trying to resolve, as "maximum call stack exceeded" is a pain to trap.
marijnh commented 2025-03-17 21:47:47 +01:00 (Migrated from github.com)

Attached patch should help.

Attached patch should help.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
marijn/getdocs-ts#4
No description provided.