What Is TypeScript, and Why Use It?
TypeScript adds static types to JavaScript and checks them before your code runs. Learn what it is, what it catches, what it costs and when to use it.

If you write JavaScript for long enough, you meet the same class of bug again and again. A function expects a string and receives a number. A property name is misspelled and the result is undefined three calls later. An object is missing a field that one code path assumed was always there. None of these are hard to fix once you see them, but you only see them when the program runs, often in production. TypeScript exists to move that discovery earlier. This post explains what TypeScript is, what it does and does not do, how a small example behaves, and when it is worth the extra tooling. It uses TypeScript 6.x syntax, and the language is documented in the TypeScript handbook.
What TypeScript is
TypeScript is a language that extends JavaScript with a type system. Every valid JavaScript program is a valid TypeScript program in terms of syntax, and TypeScript adds optional annotations that describe what values are expected. A tool called the compiler, tsc, reads your files, checks that the types agree and then emits plain JavaScript. The browser or Node.js runs that JavaScript, and it never sees the types.
That last point is the one beginners most often miss. Types are a development-time tool. They are erased when the code is compiled, so they cost nothing at runtime, and they also protect nothing at runtime. If a server receives a JSON body that does not match your declared type, TypeScript will not stop it, because the check happened earlier, against the code and not against the data. Types describe your intentions and verify that the code is consistent with them.
A first example
Here is a small program with a deliberate mistake. The function greets a user by name.
function greet(name: string): string {
return "Hello, " + name.toUpperCase();
}
console.log(greet("Ana"));
console.log(greet(42));The annotation name: string says the parameter must be a string, and : string after the parentheses says the function returns one. Compiling the file with tsc greet.ts reports a problem on the last line:
greet.ts(6,19): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.The compiler found the bug without running anything. In plain JavaScript the same call would fail at runtime with TypeError: name.toUpperCase is not a function, and only when that line executed. In TypeScript the error appears in your editor as you type, with the file, line and column, and the code TS2345 that you can look up.
The compiler still emits greet.js by default, because type errors do not block emission unless you set noEmitOnError. This surprises people at first. It follows from the design: TypeScript is a checker layered on JavaScript, not a gatekeeper that refuses to produce output. Most teams run the check in CI and fail the build on errors, which gives the same protection.
What it catches
Type checking finds a wide set of mistakes that are easy to make and annoying to debug. Misspelled properties are one. Given an object with a name field, writing user.nmae is an error that comes with a suggestion.
const user = { name: "Ana", age: 31 };
console.log(user.nmae);misspell.ts(2,18): error TS2551: Property 'nmae' does not exist on type '{ name: string; age: number; }'. Did you mean 'name'?Other common catches include calling a function with the wrong number of arguments, forgetting to handle null or undefined when a value may be absent, returning the wrong shape from a function, and using a value after a refactor changed its type. In a large codebase the last one is the main benefit. Rename a property or change a function signature, and the compiler lists every place that now needs attention. In plain JavaScript you rely on search and tests to find them.
The editor experience is the second benefit, and for many people it is the main one. Because the editor knows the types, it can offer accurate autocomplete, show the signature of the function you are calling, jump to definitions and rename a symbol across files safely. These features work in JavaScript too, through inference, but explicit types make them more reliable.
Types as documentation
A type signature is documentation that cannot go stale, because the compiler checks it. A function declared as function parse(input: string): Config | null tells the reader that it takes text and might return nothing, which is something a comment can say but cannot enforce. When you read unfamiliar code, signatures answer the first questions without opening the implementation.
This also helps teams. A new contributor can see what shapes flow through the system by reading type definitions, and a reviewer can see when a change widens or narrows a contract. The type of a public function becomes a visible part of the pull request.
What it costs
TypeScript is not free. You add a build step, or at least a type-check step, which means configuration in a tsconfig.json file, a compiler version to manage and some extra setup in your tooling. Many tools handle this for you, and newer versions of Node.js can run files that use only erasable type syntax by stripping the annotations, so the step is smaller than it used to be. A native port of the compiler, released as TypeScript 7, aims to make checking faster, and it checks the same language, so what you learn here carries over.
There is also a learning cost. The basics are easy: annotate parameters, describe object shapes with interface or type, and use unions such as string | number. The advanced features, such as generics, conditional types and mapped types, take longer, and you can build a useful project without most of them. Start with the basics and add features when a real problem calls for them.
A third cost is false confidence. A green compile means the code is consistent with its declared types, not that the program is correct. Types do not replace tests, and they do not validate data from outside. For input from a network or a file, you still need runtime validation, and a validation library can derive a type from its schema so the two agree.
When it is worth it
TypeScript pays off most in code that is large, long-lived or shared by several people. The cost of a type is paid once, when you write it, and the benefit is collected every time someone reads, changes or refactors the code afterwards. Libraries benefit especially, because their users get autocomplete and checking for free.
For a small script, a prototype or a one-off, plain JavaScript is often the better choice. The overhead of configuration may exceed the bugs it prevents. There is also a middle path: JavaScript files can opt in to checking with a comment and a configuration option, which gives some of the benefit without renaming files. Pick based on how long the code will live and how many people will touch it, not on fashion.
How to start
Install the compiler as a development dependency, create a configuration file and turn on strict mode, which enables the checks that deliver most of the value.
npm install --save-dev typescript
npx tsc --initIn the generated tsconfig.json, make sure "strict": true is set. Rename one file from .js to .ts, fix the errors that appear, and repeat. Converting a project gradually, file by file, works well, and you can allow JavaScript files to coexist while you do.
Resist the urge to silence errors with any. The any type turns checking off for a value, and it spreads: anything derived from an any is also unchecked. Use it as a last resort, and prefer unknown, which forces you to check a value before using it.


