header ad

TypeScript First App

TypeScript First App

TypeScript First App – You’ll learn how to write the Hello World program in TypeScript in this tutorial. Learn how to set up a workspace for our source code as well as how to code our first app.

We’ll need to set up a workspace before we can start writing our first TypeScript app. A workspace is basically a folder on our system that holds all of the TypeScript files that make up our app.

header ad
  • On the Desktop, create a single folder called ‘LearningTS.’
  • In your IDE, open the folder as a project/workspace.

Typescript First app: Hello World

Now that we’ve got a Workplace, make a new file called "app.ts" in your IDE. A TypeScript file has the.ts extension. Now, in the app.ts file, type the following source code:

function logger() {

  console.log("Hello, World!");
}

logger();

Now that we’ve got some source code, we can compile our code to make it executable on the system. If you’re using Visual Studio Code, follow these steps: To create a new terminal, go to Terminal > New Terminal. The terminal window will automatically expand below the code editor and point to the current folder you’re working in.

To compile the app.ts file, type the following command in the Terminal:

tsc app.ts

The TypeScript script will be converted to a Javascript script with this command. In Project Explorer, a new file named ‘app.js’ should appear.

How to run a Javascript script that has been compiled

TypeScript cannot be run directly in the browser. The Javascript file that was generated from the TypeScript one must be run. To run the created Javascript file, type the following command in the Terminal.

header ad
 node app.js

You will see the word “Hello World” in the console.

Conclusion

Congratulations on your first TypeScript application. You learned how to write the first TypeScript program, Hello, World!, which runs on a console terminal. Obviously, it’s not that exciting, but it demonstrates how simple TypeScript is.

In This Module

Leave a Comment

Your email address will not be published.