window.LoopTrap does not exist on type Window

313 views
Skip to first unread message

Ümit Dönmez

unread,
Jul 15, 2021, 4:25:22 AM7/15/21
to Blockly
I am getting this error when injecting Blockly in Angular.

TS2339: Property 'LoopTrap' does not exist on type 'Window & typeof globalThis'.

Don't know how to  solve this one.
Any help?

feni...@google.com

unread,
Jul 15, 2021, 4:19:15 PM7/15/21
to Blockly
We use LoopTrap in one of our demos but not in core. Is it possible you copied in some code that you didn't mean to?

We do have an angular example that you can check out for starter code.

Rachel

Ümit Dönmez

unread,
Jul 15, 2021, 4:35:06 PM7/15/21
to Blockly
Yes, I took the demo as base. And when I use it in Angular I get that error.
I have this in my component.ts

const runCode = () => {
window.LoopTrap = 1000;
Blockly.JavaScript.INFINITE_LOOP_TRAP =
'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
var code = Blockly.JavaScript.workspaceToCode(this.workspace);
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
try {
eval(code);
} catch (e) {
alert(e);
}
}

Maribeth Bottorff

unread,
Jul 16, 2021, 8:22:14 PM7/16/21
to Blockly
It looks like that's a TypeScript error and the demo code you copied probably does not play out of the box with TypeScript. Unfortunately I don't know enough TypeScript to know exactly how to fix this but this stack overflow seems relevant: https://stackoverflow.com/questions/12709074/how-do-you-explicitly-set-a-new-property-on-window-in-typescript "Basically you need to extend the existing window interface to tell it about your new property." Maybe that helps? good luck,

Maribeth

Ümit Dönmez

unread,
Jul 17, 2021, 5:57:14 AM7/17/21
to Blockly
thanks!

(window as any).LoopTrap

solved it

Reply all
Reply to author
Forward
0 new messages