Learn TypeScript in Construct, part 1: Getting started

UpvoteUpvote 9 DownvoteDownvote

Index

Features on these Courses

Attached Files

The following files have been attached to this tutorial:

.c3p

learn-ts-part-1.c3p

Download now 50.36 KB

Stats

359 visits, 478 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY-NC 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 19 Jun, 2025.

Using developer tools

The browser console is part of the browser's developer tools, or "dev tools" for short. Getting to developer tools might seem like a bit of a detour when you're just getting started, but it's well worth it, for two reasons:

  1. Developer tools, and things like logging messages to the console, are an essential part of the day-to-day work of programming. It's definitely worth learning about them and getting familiar with how they work.
  2. The browser console is also a really useful tool for helping you try out code snippets. We'll try that out later on.

Opening dev tools

You can open dev tools for any browser window or tab. However we only want dev tools for the preview window where your project runs, as that's where your TypeScript code runs too. While you can open dev tools for the Construct editor, it's not useful here.

So first of all preview your project by clicking the "Play" icon in the toolbar near the "Menu" button. (You can also preview by pressing F5.)

The Preview button in Construct 3

Construct will open a popup window with a blank white screen, as there's nothing in the layout. Make sure the preview window is the active window - you can click inside the preview window to make sure it's the active window - then:

  • In Safari, press Command + Option + I.
  • In any other browser, press F12.

A new window should open for the browser developer tools. Click the Console tab near the top to make sure you're viewing the list of console messages. You should see Hello world! in the list of messages! There may be some other messages that Construct logged itself, but you can ignore those.

The browser developer tools console

Congratulations! You have run your first line of TypeScript code and seen the message it logged.

Changing the message

In Construct you can try changing the message that is logged. (Remember to double-click the script block to edit it, and click outside to finish.) Any text between the double quotes will be shown in the console. For example you could try:

console.log("My super cool message!");

Preview the project, open dev tools, and you can see your updated message.

Testing code in the console

As mentioned previously, a great feature of the console is that you can also try out code snippets - you can type in code and see it run immediately. This is a very handy way to try things out. At the bottom of the list of messages in the console should be an input field where you can enter some code.

However when you type code directly in to the browser, you can only write JavaScript code. Let's quickly cover why this is.

How TypeScript works

Browsers don't actually have built-in support for TypeScript - they can only directly run JavaScript. When you write TypeScript code and then want to run it, a special program called the TypeScript compiler (or tsc for short) converts - or "compiles" - your TypeScript code to JavaScript. Remember that TypeScript is an extension to JavaScript that adds types. Compiling TypeScript to JavaScript pretty much involves just deleting type annotations. We haven't covered those yet, but in short it means deleting the bits that TypeScript adds to JavaScript, and so the JavaScript output of your TypeScript code will look very similar.

Construct has a built-in version of the TypeScript compiler, and it automatically converts your TypeScript code to JavaScript for you, so you don't have to worry about that. Then the browser will run the resulting JavaScript code. However if you type code directly in to the browser, such as in the console, the browser does not support TypeScript nor does it run the TypeScript compiler, and so you can only enter JavaScript code.

We haven't actually covered anything specific to TypeScript in this guide yet - the console logging code snippet happens to be identical between JavaScript and TypeScript, and many more snippets also happen to be identical. This is just something to bear in mind and we'll explain more about the difference between TypeScript and JavaScript later on.

Back to the console

So bearing in mind the console only supports JavaScript, let's turn our attention back to it. Try typing 1 + 1 and press Enter. It will instantly run this as JavaScript code and log the result.

Writing code in the console

You can also try entering the console log code inside the console, and see it print the message there.

Logging to the console from the console

You can enter JavaScript code in to the console this way at any time and immediately see the result - or an error if you entered something incorrectly. As mentioned you cannot enter TypeScript code here, but it's still very useful for exploring things like the library of built-in functions that browsers provide. This makes it a great way to quickly experiment with lots of different variations of code. Do feel free to try it out at any point during this guide and play with different code samples - it's a great way to learn more.

Conclusion

In this part we've covered:

  • About this guide, and what you'll learn in this series
  • How to add some TypeScript code in an event sheet in Construct
  • Using console.log() to add a message to the browser console
  • How to open the browser developer tools and view the console
  • How to enter code in the console to quickly try it out - bearing in mind that browsers only directly support JavaScript, not TypeScript.

This guide will often use the browser console for logging the results of code, and it provides an excellent place to experiment with code, so it's worth the time to get familiar with it.

You can download a Construct project file for this part of the guide here:

.C3P

learn-ts-part-1.c3p

Download now 50.36 KB

Next Tutorial In Course

Learn TypeScript in Construct, part 2: language basics 19:40

Learn some of the basic features of the TypeScript programming language, such as comments, variables and data types.

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Im started with it, Lets begin with typescript 🌝

  • it's not really clear for me how to use the behaviours events. Does anybody has any information about it and about construct 3 life circle. I can't find appropriate information about it