karakum-team / karakum

Converter of TypeScript declaration files to Kotlin declarations
Apache License 2.0
42 stars 2 forks source link

Error: Unhandled vararg declaration for args parameter #3

Closed shubhamsinghshubham777 closed 1 year ago

shubhamsinghshubham777 commented 1 year ago

Hi there I am trying to use this plugin to generate Kotlin declarations for https://www.npmjs.com/package/@jitsi/react-sdk

I followed the readme and this is how my karakum.config.json file looks like:

{
  "input": "node_modules/@jitsi/react-sdk/lib/components/JitsiMeeting.d.ts",
  "output": "generated",
  "libraryName": "@jitsi/react-sdk"
}

But when I try running the following command: npx karakum --config karakum.config.json, I get the following error stack:

shubhamsingh@Shubhams-MacBook-Pro test_react % npx karakum --config karakum.config.json
Plugin file: /Users/shubhamsingh/IdeaProjects/test_react/karakum/plugins/convertNamespace.js
Source files root: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@jitsi/react-sdk/lib/components/
Source files count: 64
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/react/global.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/react/global.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/csstype/index.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/csstype/index.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/prop-types/index.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/propTypes/index.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/scheduler/tracing.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/scheduler/tracing.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/react/index.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/react/index.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@jitsi/react-sdk/lib/types/JitsiMeetExternalApi.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@jitsi/reactSdk/lib/types/JitsiMeetExternalApi.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/node/assert.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/node/assert.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/node/assert/strict.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/node/assert/strict.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/node/globals.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/node/globals.kt
Source file: /Users/shubhamsingh/IdeaProjects/test_react/node_modules/@types/node/async_hooks.d.ts
Target file: /Users/shubhamsingh/IdeaProjects/testReact/nodeModules/@types/node/asyncHooks.kt
Error: Unhandled vararg declaration for args parameter
    at convertParameterDeclarationWithFixedType (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/plugins/convertParameterDeclaration.js:87:19)
    at Object.render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/plugins/convertParameterDeclaration.js:15:12)
    at render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/render.js:13:35)
    at CommentsPlugin.render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/plugins/CommentsPlugin.js:29:43)
    at render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/render.js:13:35)
    at /Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/plugins/convertFunctionType.js:21:110
    at Array.map (<anonymous>)
    at Object.render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/plugins/convertFunctionType.js:21:93)
    at render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/render.js:13:35)
    at CommentsPlugin.render (/Users/shubhamsingh/IdeaProjects/test_react/node_modules/karakum/build/converter/plugins/CommentsPlugin.js:29:43)

I'm not sure how to proceed forward. Any help would be appreciated ⭐

P.S. this his how my convertNameSpace.js file looks like:

const ts = require("typescript");

module.exports = (node, context, render) => {
    if (ts.isModuleDeclaration(node) && ts.isModuleBlock(node.body)) {
        return node.body.statements
            .map(statement => render(statement))
            .join("\n")
    }
    return null
}
sgrishchenko commented 1 year ago

I believe problem is here

executeCommand: (name: string, ...args: any[] | undefined[]) => void;

Type any[] | undefined[] is probably rendered to Any, because Kotlin does not support unions.

In Kotlin for such declaration:

function (...args: string[])

Karakum should generate something like this

fun (vararg args: String)

So I need to extract generic type from args but I can not extract generic type from Any. To move forward you can write custom plugin to handle this case.

What behavior do you expect in such situation? Somthing like that:

fun executeCommand: (name: string, vararg args: Any) => void;
shubhamsinghshubham777 commented 1 year ago

What behavior do you expect in such situation? Somthing like that:

fun executeCommand: (name: string, vararg args: Any) => void;

Yes, I would want something like this only ✅

sgrishchenko commented 1 year ago

Fixed in 070eb337ec2242264720160d2a0a0d9642088dc7