Dive into TypeScript: Writing Your First Program

Welcome back to our TypeScript journey! In this blog post, we’ll dive right into the exciting world of TypeScript programming by writing your first TypeScript program. Get ready to experience the power and simplicity of TypeScript syntax!
Writing Your First TypeScript Program
Let’s start with a simple “Hello, World!” program. Create a new file with a .ts
extension (e.g., hello.ts
) and add the following code:
function greet(name: string): string {
return "Hello, " + name + "!";
}
console.log(greet("World"));
Save the file and open your terminal. Navigate to the directory containing your TypeScript file and run the following command:
tsc hello.ts
This command will compile your TypeScript code into JavaScript. Once the compilation is successful, you’ll see a new file named hello.js
in the same directory.
Now, let’s execute our program by running:
node hello.js
You should see the output:
Hello, World!
Congratulations! You’ve just written and executed your first TypeScript program.
What’s Next?
Now that you’ve got a taste of TypeScript, the possibilities are endless. In the next blog post, we’ll explore basic syntax and TypeScript features in more detail. Stay tuned for more TypeScript goodness!