I am trying to generate code from blocks that can have any input type to JavaScript. But to do so I need to know what type these blocks are during generation time.
Most blocks already have a type internally for the type check
"output": ["Integer","Number"],
or
this.setOutput(true, 'String');
but I can't find a function to access the 'output' field with.
Ideally I want to access the type in the generator function like this:
var return_type = block.getChildren()[0].functionToAccessOutputWith;
There is the '.type' field but that one gives the name of the block type not the return value defined with output.
It seems like a very common problem but I can't find anything online.
Just trace through the source code by following the function calls of
Block.setOutput()
. It's not that hard. Eventually you will reach a line inBlockly.Connection
that saysthis.check_ = check;
So what you are looking for is basically
block.outputConnection.check_
. But this is not a function and the_
indicates that it is supposed to be a private property. For convenience I'd write a getter function into Block.