-
Notifications
You must be signed in to change notification settings - Fork 5
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
How to add typegen for custom plugins? #36
Comments
Hey, yes, this is possible, but you'll need to upgrade to Kea v3 (out in a few hours). The new docs reference a few examples you can look at: https://v3.keajs.org/docs/intro/typescript#create-logic-builder-type-builders It's not a lot, but it's something :). |
Hey, thanks a lot for the fast response. I just found out it is also possible in v2, isn't it? I started writing something like this: https://github.com/keajs/kea-typegen/blob/main/form-plugin/lib/form-plugin/src/typegen.js However, I'll wait for Kea 3. Excited about the new update. We haven't released the product yet, so it'd be awesome if we could upgrade to v3 before the release. Thanks for your help and the awesome library. |
Well, 3.0.0 is out now. :) |
I upgraded to 3.0.0, however, having an issue with the file. I am not sure if this is a bug or an issue on my side. This is the error I get when running the typegen SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1032:15)
at Module._compile (node:internal/modules/cjs/loader:1067:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at visit (/path/project-hyvor-blogs/node_modules/kea-typegen/dist/src/visit/visit.js:89:73)
at visitNode (/path/project-hyvor-blogs/node_modules/typescript/lib/typescript.js:30043:24)
💚 18 logic types up to date! As you can see, this happens in the My typegen file looks like this: import {VisitKeaPropertyArguments} from "kea-typegen";
import ts from 'typescript';
export function ajax({ name, parsedLogic, node, type, getTypeNodeForNode, prepareForPrint } : VisitKeaPropertyArguments) {
// TODO:
} Any idea why this happens? The documentation you linked, says |
Never mind, got everything working. It was exciting to work with the TS compiler API ;) I open sourced the code. https://github.com/hyvor/kea-ajax It's a simpler version of kea-loaders. |
@supunkavinda could you please share the solution for that error? SyntaxError: Cannot use import statement outside a module And i'm having a hard time figuring it out. |
I had to compile TS to JS before running kea-typegen. You can find tsconfig here: https://github.com/hyvor/kea-ajax/blob/main/tsconfig.json Edit: Actually, I am not sure what fixed that issue. Earlier, the kea plugin was inside our main project when I had that problem. Later I created a new repo for the plugin and didn't have that issue again. |
@mariusandra could you maybe elaborate on that topic? Is it necessary to have the plugin for Kea in a separate library? Or is there some way to have it in the main project? |
Hey @supunkavinda, this is awesome! I added your package to Kea's homepage under a new "community" line. Also, indeed, the @rschyboll It should also be very possible to have your plugin and typegen code inside the main project itself. Check out the I'm not sure what was the cause of the import error. Possible something with TS config? I'm not sure, but would happily help debug if you can provide a reproducible repo :). |
Hi! Sorry for the late answer, in the end, i resigned from using plugins in my project for now, mostly because of time constraints. |
Hello,
I've written a simple plugin that adds a few reducers, actions, and listeners. Is there a way to tell
kea-typegen
"there's a custom plugin, and here's how to generate types for that plugin"?I don't see any documentation on this.
The text was updated successfully, but these errors were encountered: