Typescript in Generators

88 views
Skip to first unread message

Julian

unread,
Oct 28, 2021, 8:28:27 AM10/28/21
to Blockly
I created a jsonGenerator which is fully working but now i wanted to transform my JS file into a Typescript file. The problem I then encounter is that Blockly ofcourse doesnt know Blockly.JSON because I just created it. However in blockly.d.ts there are types for all functions you can use in the generator for functions like statementToCode. I want Blockly to know that there is a new generator and that I can use the types of the module Generator ( That is what I think would work, but I don't know how ). Or another solution maybe to create an own interface or module or type (I am pretty new to typescript btw ).

In this image it shows where the error is.error1.png
Here it shows the message.

Kind regards,

Julian

Coda Highland

unread,
Oct 28, 2021, 11:13:45 AM10/28/21
to blo...@googlegroups.com
That's not possible in TypeScript. You can't modify the definition of a type after it's been created, and the type of a module is defined by the exports in the module file. Think about it -- how would code in a third file be able to know what type Blockly.JSON is?

However, there's also no specific need for your generator to be added to the Blockly namespace. If you're using modules, then code that wants to use the JSON generator can just import it directly. So instead of "Blockly.JSON =", just use "export default".

/s/ Adam

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/bd1827a5-c037-409d-bd85-2b524f56daefn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages