Custom code generator : Typescript & React

250 views
Skip to first unread message

Ciberdead

unread,
Apr 28, 2023, 10:46:54 AM4/28/23
to Blockly
Hi, i've got an issue with custom code generator, when i'm making a custom generator i've got this issue on every block that i want to define the code generation : 
Element implicitly has an 'any' type because expression of type '"union"' can't be used to index type 'CodeGenerator'.
  Property 'union' does not exist on type 'CodeGenerator'.ts(7053)

Here is my code :
https://pastecode.io/s/cax0614b

The strange thing is, for the javascriptgenerator, it works perfectly, but not for the custom one

Maribeth Bottorff

unread,
Apr 28, 2023, 1:00:26 PM4/28/23
to Blockly
Hi,

We're still working out some issues with our TypeScript definitions in some areas of the codebase where the old approach in JS doesn't translate super well to TS. Generators are one of those areas. The existing generators like the javascriptGenerator are just typed as `any`, which is why you don't see that message. You could do the same for your sampleGenerator for now. Converting the generators to TS and improving the types in that area is on our roadmap this year.

Maribeth

Ciberdead

unread,
May 4, 2023, 7:06:18 AM5/4/23
to Blockly
I've added the "any" type to my sample generator, but when i'm trying to generate some code, it shows me only the first block and does not go to the next block.

Ciberdead

unread,
May 4, 2023, 7:08:01 AM5/4/23
to Blockly
Here is my code, i'm trying for now to make both generator the same code which is relational algebra.. 
https://pastecode.io/s/srea0rwm

Maribeth Bottorff

unread,
May 4, 2023, 5:29:10 PM5/4/23
to Blockly
By default, a generator will only get the code for the block it was called on. If you want to get the code for connected blocks, you need to set this up yourself. This is commonly done in the `scrub_` function for the generator. This is covered in the codelab here. You also might want to read through the code for the existing generators to see if there is anything else your custom generator needs to do like set up variables, reserve keywords for your language, etc. Not all of the setup is covered by just calling the Generator constructor.

Maribeth

Ciberdead

unread,
May 9, 2023, 5:21:44 PM5/9/23
to Blockly
Solved : here is what i've done for my custom generator, seems a bit overkill for the little that i need to do, definitly need a simpler version for thoses who want easy to user custom generators. And in the documentation, their is a lack of information about it. Still, their is a couple of FIXME in the code that a due to the changes in the import changes that i've done, could need some clarification for this.
https://pastecode.io/s/ne1ynr1e
Reply all
Reply to author
Forward
0 new messages