TypeScript
Here’s a concise MediaWiki-style page about TypeScript based on your request:
Contents
About
TypeScript is a strongly typed superset of JavaScript that compiles to plain JavaScript. Developed by Microsoft, it adds optional static typing, interfaces, and other features to enhance code quality and maintainability. TypeScript is often used with a framework for building user interfaces like React.
Child Pages
Related/Child Pages:
- General:
- TypeScript Constructs - some constructs in the TypeScript language.
- TypeScript Cheatsheet - a handy TypeScript reference guide.
Installing TypeScript
To get started with TypeScript, you need to install the TypeScript compiler. The easiest way is using npm:
$ npm install -g typescript
Verify the installation:
$ tsc --version
You can now compile TypeScript files (.ts) into JavaScript using:
$ tsc file.ts
Creating a Hello World in TypeScript
To create a basic TypeScript program, follow these steps:
hello_world.ts:
const greet = (name: string): string => { return Hello, ${name}!; };
console.log(greet(“World”));
Compile the file and run it using Node.js:
$ tsc hello_world.ts $ node hello_world.js
TypeScript Templates
Hello World
const helloWorld = (): void => {
console.log(“Hello, World!”);
};
helloWorld();
Basic Types
let isDone: boolean = false;
let count: number = 42;
let name: string = “TypeScript”;
let list: number[] = [1, 2, 3];
let tuple: [string, number] = [“hello”, 42];
Interfaces and Classes
interface Person {
name: string;
age: number;
}
class Student implements Person {
constructor(public name: string, public age: number) {}
greet(): string {
return Hi, I'm ${this.name}.;
}
}
const student = new Student(“Alice”, 20);
console.log(student.greet());
Links
This streamlined page introduces TypeScript and includes key setup instructions and examples while keeping the structure simple. Let me know if you’d like any further refinements!