Released · improving
Programming language · Since 2012
TypeScript adds static types to JavaScript, catching errors before your code runs and making large codebases easier to maintain.
TypeScript is an open-source language created by Microsoft and first released in 2012. It is a superset of JavaScript, so existing JavaScript code is already valid TypeScript, and it adds type annotations, interfaces, generics and more on top. The compiler checks your types and then emits plain JavaScript with the types removed, so the result runs anywhere JavaScript does, from browsers to Node.js.
Type checking catches typos, wrong arguments and access to undefined values before the code ever runs. Editors use the same type information to power accurate autocompletion, renaming and go-to-definition. That pays off most in web apps, servers and libraries that many people work on over a long time.
Start with the basics of JavaScript, then work through the official Handbook. The TypeScript Playground lets you write code and inspect the compiled output without installing anything, and an existing JavaScript project can adopt TypeScript gradually by converting a few files to .ts at a time.
Finds code with mismatched types before it runs, reducing runtime errors.
You don't have to annotate everything: the compiler works out types from values and context.
Use any existing JavaScript library and introduce TypeScript into an ongoing project step by step.
Unions, generics and conditional types let you describe complex data structures and APIs precisely.
Download and install the LTS release from nodejs.org; on macOS and Linux a package manager works too. Then check that the version prints in your terminal.
node --versionIn your project folder, install TypeScript as a development dependency. A per-project install keeps everyone on the team on the same compiler version.
npm install --save-dev typescriptRun the project's tsc through npx and make sure it prints a version.
npx tsc --versionThe greet function declares that its name parameter and its return value are both strings. npx tsc hello.ts checks the types and produces hello.js, and node hello.js prints Hello, TypeScript!. Passing a number, as in greet(42), is reported as an error at compile time.
hello.ts
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("TypeScript"));npx tsc hello.ts && node hello.jsSix chapters that take you from installation to the core ideas of TypeScript.
Ask questions, share experience and trade opinions about TypeScript.
No discussions yet. Start the first one.
0 comments
Sign in · Sign in to leave a comment.
Be the first to comment.