Start here
TypeScript is a programming language and set of developer tools built on JavaScript. You write familiar JavaScript plus optional information about the kinds of values your code expects. TypeScript checks that information before the program runs, then produces JavaScript for the browser or another JavaScript runtime.
You do not need to master every type feature to begin. Read the first program below, learn what an annotation and a compiler do, then move to basic types, functions and object shapes. If JavaScript itself is new to you, the JavaScript introduction is a useful first stop.
- Start with JavaScript
- Compare JavaScript and TypeScript
- See how TypeScript becomes JavaScript
- Set up on Windows
- Set up on macOS
- Set up on Linux
- Build your first TypeScript project
- Understand tsconfig.json
- Build a browser page
- Try the Codectionary Playground
- Continue with basic types
- Function types
- Object shapes with interfaces
Why TypeScript was created
Microsoft developed TypeScript, with Anders Hejlsberg serving as its lead architect. It was first released publicly in October 2012. JavaScript was already being used for increasingly large applications; teams needed stronger tools for understanding how pieces of those applications fit together and for finding mistakes while editing.
TypeScript added static checking and editor support while keeping a close relationship with JavaScript. A JavaScript developer can adopt it gradually rather than replace an entire application at once. As projects and teams grew, explicit descriptions of shared data and function inputs became useful for changing code with more confidence. Those descriptions do not replace reviews or tests.
What static types and annotations mean
A type describes what kind of value an expression can hold or what operations are expected to work on it. Static checking examines source code before it executes. For example, TypeScript can flag a call that passes a number to a function expecting a string. JavaScript would normally discover the mismatch only when the affected code runs, if it fails at all.
A type annotation writes an expected type in the source. In name: string, the colon and string tell the checker that name should be a string. Annotations are optional in many places: TypeScript can often infer a type from a value, such as inferring that const count = 3 is a number. The checker also examines how values move through assignments, calls and returns. It reports possible mismatches; it cannot prove that every runtime behaviour will be correct.
From TypeScript source to running JavaScript
A compiler is a tool that reads source code and produces another form of code. The TypeScript compiler, often called tsc, checks a project and can emit JavaScript files. A tsconfig.json file can control which files it reads, how strict the checks are and what JavaScript it produces. Some build tools only remove TypeScript syntax, so transpiling a file is not necessarily the same as type-checking the whole project.
Type annotations, interfaces and other type-only declarations are removed from the JavaScript output. Runtime instructions such as function calls remain. A normal browser runs the emitted JavaScript; do not expect it to execute a .ts file containing TypeScript annotations directly. Node.js is another JavaScript runtime and can run suitable JavaScript output. The target runtime still determines which web or server APIs are available.
A diagnostic is a message from the compiler about a possible problem. Whether a tool emits JavaScript after diagnostics depends on its configuration; a failed check is not automatically a guarantee that no file was emitted. Fix reported errors, then test the actual output in the environment where it will run.
Type checks are not runtime validation
TypeScript checks the assumptions it can see in source code. Its types are erased before the JavaScript runs, so they cannot inspect a response from an API, a form submission or a file at runtime. A declaration that data has a certain shape does not make an untrusted value match it.
For example, before using an API response as a user record, check at runtime that it is an object and that its required fields have suitable values. Then handle invalid input. TypeScript can help you describe the validated value after that check, but it does not perform the validation for you. Automated tests are still needed for behaviour, integration and edge cases.
Where TypeScript is used
TypeScript helps where a JavaScript project has many related values, functions or contributors. It does not supply a browser, server or framework on its own; those environments and tools are separate choices.
| Use | Why types can help | Example |
|---|---|---|
| Frontend web development | Describe component state and browser-facing data. | Catch a mistaken property name in a product-list filter. |
| Large web applications | Keep the contracts between features visible as the code grows. | Change an order status model and find affected screens. |
| React and other supported frameworks | Check component props and event handlers when the toolchain supports TypeScript. | Require a profile card to receive a user name. |
| Backend and Node.js applications | Describe service inputs, results and internal data. | Check that an order function receives the expected fields. |
| APIs | Share or generate types for request and response shapes. | Align a client model with a documented endpoint; validate real responses separately. |
| Team projects | Make assumptions easier to inspect during editing and review. | Show a teammate what a function accepts and returns. |
| Migrating JavaScript | Adopt checking gradually instead of rewriting every file at once. | Convert one module and its boundaries before expanding coverage. |
Benefits, limitations and choosing JavaScript
TypeScript can catch many mismatched calls and property accesses before execution. Its editor feedback, navigation and refactoring tools can make changing a large codebase easier. Types also document some expectations for teammates. These benefits are strongest when important values and boundaries have accurate types and the project actually runs a type checker.
It adds learning and tooling work: you must understand enough JavaScript first, configure a compiler or build tool, and maintain useful type definitions. Incorrect assertions or broad any types can hide mistakes. Compilation does not guarantee correct logic, secure code or valid external data. Runtime and browser compatibility still depend on the JavaScript you emit and the APIs you use.
Plain JavaScript can be enough for a small script, a first browser exercise or a project where the extra checking does not justify the setup. JavaScript can also use editor checking through JSDoc in some projects. Choose TypeScript when its feedback and shared contracts solve a real maintenance problem, not because every JavaScript program requires it.
Read your first TypeScript program
The example below defines greet with a parameter named name. Its : string annotation says the input is a string, and the annotation after the closing parenthesis says the function returns a string. The return statement combines text with name. Calling greet("Ada") produces Hello, Ada!, which console.log writes to the preview console.
Try changing the call to greet(42). A full TypeScript type check reports that a number is not assignable to the string parameter. In Codectionary’s example runner, TypeScript is transpiled for a browser preview without a full project type check, so use a local checker to verify this diagnostic. The emitted JavaScript has no : string annotations; it runs the concatenation at runtime. Try a valid second name and compare the output.
Syntax
function greet(name: string): string {
return "Hello, " + name + "!";
}
console.log(greet("Ada"));Examples
Greet someone with a typed function
A small typed function. The browser preview prints Hello, Ada! after the TypeScript syntax is removed.
function greet(name: string): string {
return "Hello, " + name + "!";
}
console.log(greet("Ada"));- The name: string annotation describes the accepted argument. The : string after the parameter list describes the returned value.
- return builds a greeting from two strings and the name argument. greet("Ada") passes a valid string, so the call satisfies those declarations.
- console.log writes Hello, Ada! to the preview console. The type annotations disappear from the emitted JavaScript; the function call and string concatenation remain.
- A full type check flags greet(42), but this browser preview only transpiles the example. Test the code and validate external inputs in the runtime as well.
TypeScript: background & uses
- Used for
- Large web applications, Shared API types, Developer tooling
- Created by
- Microsoft, with Anders Hejlsberg as a key designer
- First released
- 2012 · first public release
- Version / standard
- TypeScript 7.0
Current stable release line. Your project may use an earlier compiler.
In the real world
Facts checked 8 September 2026. Product links describe documented uses.
Best practices
- Learn JavaScript values, functions and objects alongside TypeScript syntax.
- Run a project type check; transpiling a file alone does not verify its types.
- Validate untrusted data at runtime before relying on its shape.
- Test the emitted program in the browser or runtime you intend to support.
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook