Menu

TypeScript Explained: Types That Catch Bugs Before They Run
📰

TypeScript Explained: Types That Catch Bugs Before They Run

DEV Community: typescript·The Practical Developer·about 1 hour ago
#Qvkkkpdd
#devtotypescript#devto#dev#user#string
Reading 0:00
15s threshold

Introduction

JavaScript lets you pass anything to a function — a number, a string, or nothing at all — and only complains when the code actually runs. TypeScript adds a layer on top: you describe what shape your data should have, and the editor warns you the moment you get it wrong.

TypeScript does not replace JavaScript. It compiles down to plain JavaScript, so it runs everywhere JavaScript runs. You are adding safety checks, not learning a new language from scratch.

Your first type annotation

A type annotation is just a label after a variable or parameter, saying what it should be.

function greet ( name : string ): string { return `Hello, ${ name } !` ; } greet ( " Sara " ); // Works greet ( 42 ); // Error: Argument of type 'number' is not assignable to 'string'

Enter fullscreen mode

Exit fullscreen mode

That error appears in the editor before you run anything.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.