TypeScript checks type relationships before your JavaScript runs; it does not change JavaScript’s runtime behavior. For a practical refresher, revisit primitive types and inference, function signatures, object shapes, union narrowing, and then generics. The official Handbook is a strong starting point for everyday TypeScript, with reference pages for finer details.
What TypeScript does—and what it does not do
TypeScript is a static typechecker for JavaScript. It checks whether values are used consistently with their types before the program runs. It does not replace knowledge of JavaScript or turn runtime behavior into something different. A type check in your code also does not, by itself, validate arbitrary data arriving from a network or other external source.
The TypeScript Handbook is designed for everyday programmers and offers a guided overview of common syntax and behavior. It is not the language specification or an exhaustive reference. If you are new to JavaScript itself, the Handbook recommends learning JavaScript first.
Start with primitive types and inference
The familiar JavaScript primitives include strings, numbers, and booleans. Their TypeScript type names are lowercase: string, number, and boolean. The primitive symbol type is symbol.
#1 Best Overall
let username = "Mina"; // inferred as string
let score: number = 42;
let isReady: boolean = true;
When a local value’s type is obvious from its initializer, TypeScript can infer it; there is no need to annotate every variable mechanically. An explicit annotation can still help make intent clear, especially at function boundaries or where the expected type is not evident.
Use primitive lowercase names rather than boxed types such as String, Number, Boolean, and Symbol. The official guidance also cautions against using the global Object as an ordinary annotation type. See TypeScript’s Do’s and Don’ts for the rationale.
Annotate function inputs and outputs
Parameter annotations let TypeScript check calls. Return annotations describe what a function produces and can make a function’s contract clearer to readers.
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
function greet(name: string): string {
return `Hello, ${name}`;
}
greet("Sam");
// greet(42); // Type error: a number is not a string
void is commonly used as a return type when a function does not return a meaningful value to its caller:
Recommended Free Tools
function logMessage(message: string): void {
console.log(message);
}
This annotation describes the function’s type-level contract; it does not alter the fact that the function runs according to JavaScript’s runtime rules. The Handbook’s Everyday Types chapter covers common types and where annotations belong.
Describe the shape of an object
An object type describes the properties a value is expected to have and the type of each property. For a one-off shape, write it inline:
function printUser(user: { name: string; active: boolean }): void {
console.log(user.name, user.active);
}
If the shape needs a name, you can define it with an interface or a type alias. Both make the property contract easier to reuse:
interface User {
name: string;
active: boolean;
}
type UserRecord = {
name: string;
active: boolean;
};
Choose the form that suits your codebase and the role of the type; the key idea is that the annotation describes the object’s properties. The Objects chapter explains these forms.
Use unions, then narrow before type-specific work
A union type expresses alternatives. A value typed string | number may be either a string or a number, so code cannot safely assume it supports operations specific to only one of those types until it checks which case it has.
function formatValue(value: string | number): string {
if (typeof value === "string") {
return value.toUpperCase();
}
return value.toFixed(2);
}
TypeScript follows JavaScript control flow and narrows the type in branches where a check establishes which alternative is present. The Handbook also explains narrowing with checks such as in and instanceof; see Narrowing.
Narrowing is a type-checking aid, not a general runtime validator. If data comes from an untrusted external source, a TypeScript annotation alone does not prove that the data matches that type when the program runs.
Reach for generics when a type relationship matters
Generics let a function preserve a relationship between its input and output types. For example, a first-element helper should return the array’s element type, not discard that information as any. Because an array can be empty, its first element may be undefined:
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Best Value
function firstElement<T>(items: T[]): T | undefined {
return items[0];
}
const firstName = firstElement(["Mina", "Sam"]); // string | undefined
const firstScore = firstElement([42, 17]); // number | undefined
Here, T is a type parameter: TypeScript infers it from the array passed to the function, then carries that element type through to the return value. Use a generic when preserving such a relationship makes an API more useful than a fixed type would. The Generics chapter develops this idea.
A sensible route for a refresher
- Review primitive types and inference. Check that you recognize the lowercase primitive types and know when an annotation adds clarity.
- Practice function signatures. Annotate parameters and return types, then notice how parameter types affect which calls are accepted.
- Describe object shapes. Try an inline type before naming a reusable shape with an interface or type alias.
- Work through unions and narrowing. Make each branch establish the case before using a type-specific operation.
- Study generics after the basics. Focus on examples where a type parameter connects input and output rather than adding one without a clear relationship.
This is a practical sequence based on the Handbook’s coverage, not a mandatory path for every learner. Use the Handbook for the walkthrough, then open its reference material when a detail or edge case needs closer treatment.
Keep any from erasing useful checks
any permits operations without the usual type checks for that value, effectively turning off type checking there. It can hide mistakes rather than describe uncertainty. When a value may be of an unknown type and must be checked before use, unknown is safer: TypeScript requires you to narrow it before performing type-specific operations. The Everyday Types guide discusses both.
Optional structured practice
The free Handbook is a useful first stop; a print book may suit readers who prefer a more structured sequence and exercises. No Starch Press lists Total TypeScript: The Essentials, by Matt Pocock with Taylor Bell, as a 432-page print book published in April 2026. The publisher describes coverage of primitive types, unions, objects, classes, basic generics, and exercises. It is an optional way to practise fundamentals, not a replacement for the Handbook.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The TypeScript team’s March 5, 2021 announcement described the rewritten Handbook as the website’s primary learning resource at that time. The announcement noted web, EPUB, and PDF formats then; it does not establish current availability of each format. Read the announcement by Orta Therox for that historical context.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




