typescript

A shared tag with AI prompts and code snippets

From workspace: FreeCodeCamp

Team: Main

Total snippets: 4

FreeCodeCamp

typescript

4 snippets

Enable Strict Mode in tsconfig.json

Use strict mode to enable all core type-safety features.

{ "compilerOptions": { "strict": true } }

Compile-Time Error Example

Demonstrates how TypeScript catches type mismatch errors before runtime.

function multiply(a: string, b: string): number { return a * b; // ❌ Error: Operator '*' cannot be applied to type 'string' }

Function with Type Annotations

Define a function with typed parameters and a typed return value.

function multiply(a: number, b: number): number { return a * b; }

What Is TypeScript?

TypeScript is a superset of JavaScript that adds static type safety.

// TypeScript example vs JavaScript: let count: number = 5; // TS: type-safe let name: string = "John"; // JS would allow anything, TS enforces string