gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
give me an example of hello world in Typescript
- User
give me an example of hello world in Typescript
- Assistant
Certainly! Here's a simple example of a "Hello, World!" program in TypeScript.
First, make sure you have TypeScript installed. You can install it globally using npm if you haven't done so:
bashnpm install -g typescriptNext, create a file named
hello.tsand add the following code:typescript// hello.ts function greet(name: string): string { return `Hello, ${name}!`; } // Call the function and log the output const message: string = greet("World"); console.log(message);Now, you can compile the TypeScript file to JavaScript using the
tsccommand:bashtsc hello.tsThis will create a
hello.jsfile. You can run this file using Node.js:bashnode hello.jsWhen you run the command, it should output:
codeHello, World!This is a simple demonstration of how to write, compile, and run a TypeScript program.