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

StackOverflow with react-helmet #482

Open
BierDav opened this issue Mar 10, 2022 · 2 comments
Open

StackOverflow with react-helmet #482

BierDav opened this issue Mar 10, 2022 · 2 comments

Comments

@BierDav
Copy link

BierDav commented Mar 10, 2022

🕗 Version

dukat version 0.5.8-rc.4

💻 Code or Package Name

react-helmet

🙁 Actual behavior

When I execute: dukat ./node_modules/react-helmet/index.d.ts

I get following error:

Exception in thread "main" java.lang.StackOverflowError
        at java.base/java.util.LinkedHashMap.getOrDefault(LinkedHashMap.java:453)
        at org.jetbrains.dukat.tsLowerings.TypeSpecifierLowering.spec(TypeAliasContext.kt:20)
        at org.jetbrains.dukat.tsLowerings.TypeSpecifierLowering.lowerParameterValue(TypeAliasContext.kt:39)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerUnionTypeDeclaration(DeclarationLowering.kt:132)
        at org.jetbrains.dukat.tsLowerings.TypeSpecifierLowering.lowerUnionTypeDeclaration(TypeAliasContext.kt:15)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:239)
        at org.jetbrains.dukat.tsLowerings.TypeSpecifierLowering.lowerParameterValue(TypeAliasContext.kt:39)
        at org.jetbrains.dukat.tsLowerings.TypeAliasContext.dereference(TypeAliasContext.kt:65)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.resolveType(resolveTypeAliases.kt:46)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.unroll(resolveTypeAliases.kt:56)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.unroll(resolveTypeAliases.kt:56)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerUnionTypeDeclaration(resolveTypeAliases.kt:65)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:239)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerParameterValue(resolveTypeAliases.kt:50)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerTypeDeclaration(DeclarationLowering.kt:144)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerTypeDeclaration(resolveTypeAliases.kt:44)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:237)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerParameterValue(resolveTypeAliases.kt:50)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerUnionTypeDeclaration(DeclarationLowering.kt:132)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerUnionTypeDeclaration(resolveTypeAliases.kt:65)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:239)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerParameterValue(resolveTypeAliases.kt:50)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerTypeDeclaration(DeclarationLowering.kt:144)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerTypeDeclaration(resolveTypeAliases.kt:44)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:237)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerParameterValue(resolveTypeAliases.kt:50)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerUnionTypeDeclaration(DeclarationLowering.kt:132)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerUnionTypeDeclaration(resolveTypeAliases.kt:65)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:239)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerParameterValue(resolveTypeAliases.kt:50)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerTypeDeclaration(DeclarationLowering.kt:144)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerTypeDeclaration(resolveTypeAliases.kt:44)
        at org.jetbrains.dukat.tsLowerings.DeclarationLowering$DefaultImpls.lowerParameterValue(DeclarationLowering.kt:237)
        at org.jetbrains.dukat.tsLowerings.ResolveTypeAliasesLowering.lowerParameterValue(resolveTypeAliases.kt:50)

🙂 Expected behavior

That the command does what it's supposed to do.

Investigation

I've investigated it further. The problem seems to be related to this type: JSX.IntrinsicElements
This is part of the typescript library. Maybe there are more problems with the indirekt use of the typescript library?

It seams there is a second problem:
All the React. usages cause the same stackoverflow error.

If you remove all dependencies on JSX.IntrinsicElements and React everything works fine.

If someone knows how to make a own wrapper for this, please tell me. We need this for our project.

Update 1

Quick fix for small packages: Copy the index.d.ts to a new destination remove the import import * as React from "react"; . Run dukat and it should generate some code. Put the generated code into you project eg. wrappers. Now you have a direction for your own wrapper. There are multiple things to change before use but more than nothing.

@bobhy
Copy link

bobhy commented Nov 21, 2022

Expanding on the above workaround for:

import * as React from "react"

You may be able to minimize hand tweaking of generated definitions by hacking the source package .d.ts file(s), replacing the wildcard import with the specific references used in that file, then also changing the corresponding references to match.

I was trying to generate wrappers for @mui/x-data-grid, and found this in node_modules/@mui/x-data-grid/index.d.ts:

import * as React from 'react';
import { GridApiCommunity } from './models/api/gridApiCommunity';
. . .
export declare type GridApiRef = React.MutableRefObject<GridApiCommunity>;

Where the only reference to React in this file was React.MutableRefObject, fortunately for me. I changed that to:

import {MutableRefObject} from 'react';
import { GridApiCommunity } from './models/api/gridApiCommunity';
. . .
export declare type GridApiRef = MutableRefObject<GridApiCommunity>;

and dukat seems to have processed the whole module successfully.

Project folk: I have no idea of the complexity of a fix for this bug, but it seems multiple people have tripped over it in various guises, and React-based packages are fairly widely deployed, so it might be worth some early attention.

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