# TypeScript Fundamentals

> Annotations, inference, interfaces, unions and narrowing: the daily TypeScript every frontend job expects. Free notes, key concepts, resources and a mini...

Canonical: https://www.internhack.in/roadmaps/tracks/frontend/typescript-basics
Last updated: 2026-11-28

Annotations, inference, interfaces, unions and narrowing: the daily TypeScript every frontend job expects.

Intermediate · about 10 hours · difficulty 3/5

Learn first: [Modern JavaScript and Error Handling](https://www.internhack.in/roadmaps/tracks/frontend/modern-javascript), [JavaScript Modules](https://www.internhack.in/roadmaps/tracks/frontend/js-modules)

TypeScript is JavaScript plus a static type checker. The types are erased at build time, so nothing changes at runtime, but your editor and CI now catch typos, wrong arguments, missing null checks and broken refactors before users do. Most professional frontend codebases are written in it.

### The essentials

- **Inference first**: `const count = 0` is already a `number`. Annotate function parameters and public APIs; let the rest be inferred.
- **Object shapes** with `type` or `interface`. Either is fine; pick one convention.
- **Union types**: `type Status = "idle" | "loading" | "error"` models real states far better than booleans.
- **Optional and nullable** values: `name?: string`, `user: User | null`, with optional chaining `user?.name`.
- **Arrays, tuples and records**: `string[]`, `[number, number]`, `Record<string, number>`.
- **Narrowing**: `typeof`, `in`, equality checks and discriminated unions (`if (result.ok)`) let TypeScript know which branch you are in.

### unknown, any and assertions

`any` switches checking off and spreads silently; avoid it. Use `unknown` for data you have not validated (API responses, `JSON.parse`) and narrow it. Type assertions (`as User`) are promises you make to the compiler; they are not checks.

### Setup

Turn on `"strict": true` from day one. Use `tsc --noEmit` in CI because many bundlers strip types without checking them.

### Good enough to move on

You can type a small app's data model, functions and API responses under strict mode without reaching for `any`, and use a discriminated union for loading/success/error state.

## Key concepts

- **Type annotations and inference**
- **type aliases and interfaces**
- **Union and literal types**
- **Optional, null and undefined**
- **Narrowing and type guards**
- **Discriminated unions**
- **any vs unknown vs never**
- **Typing functions and callbacks**
- **Strict mode**

## Mini project

Port a vanilla JavaScript project (for example your fetch-based weather or movie app) to TypeScript with strict mode, typing API responses as unknown and narrowing them before use.

## Check yourself

Why is \`const data = await res.json() as User\` less safe than parsing into unknown and narrowing?

## Free resources

- [The TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html) (TypeScript)
- [TypeScript for JavaScript Programmers](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html) (TypeScript)
- [TypeScript Playground](https://www.typescriptlang.org/play) (TypeScript)

Previous: [CSS-in-JS](https://www.internhack.in/roadmaps/tracks/frontend/css-in-js) · Next: [Generics and Advanced Types](https://www.internhack.in/roadmaps/tracks/frontend/typescript-advanced)

## More in TypeScript for Frontend Developers

- [TypeScript Fundamentals](https://www.internhack.in/roadmaps/tracks/frontend/typescript-basics)
- [Generics and Advanced Types](https://www.internhack.in/roadmaps/tracks/frontend/typescript-advanced)
- [TypeScript Configuration and Tooling](https://www.internhack.in/roadmaps/tracks/frontend/typescript-tooling)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Frontend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/frontend)
