Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript support in Electron

Electron now supports typescript. But by running the example published in:

Electron official blog.

I always get the following error:

enter image description here

Should I have done something else?

like image 587
Celso França Avatar asked Oct 30 '22 02:10

Celso França


2 Answers

The support that they have for Typescript is that they provide definition files. At runtime you still have to run Javascript. Compile the Typescript to Javascript and then use the resulting .js file as your entry point.

like image 101
Titian Cernicova-Dragomir Avatar answered Nov 20 '22 16:11

Titian Cernicova-Dragomir


Install ts-node and typescript package to your project and then add parameter -r ts-node/register when running electron

npm install ts-node
npm install typescript

electron -r ts-node/register .

and add require('ts-node/register') in your html file

<script>
require('ts-node/register')
</script>
like image 23
Codler Avatar answered Nov 20 '22 17:11

Codler