A shared tag with AI prompts and code snippets
From workspace: FreeCodeCamp
Team: Main
Total snippets: 4
4 snippets
Use strict mode to enable all core type-safety features.
{ "compilerOptions": { "strict": true } }
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' }
Define a function with typed parameters and a typed return value.
function multiply(a: number, b: number): number { return a * b; }
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