TypeScript
Build speed with typed functions, interfaces, and reusable generic code.
Typed Function
आसानAdd parameter and return types to a function.
function formatPrice(
amount: number,
currency: string
): string {
return `${currency} ${amount.toFixed(2)}`;
}
const total = formatPrice(24.5, "USD");User Interface
मध्यमDescribe and format a structured user record.
interface User {
id: number;
name: string;
roles: string[];
}
function displayUser(user: User): string {
return `${user.id}: ${user.name}`;
}First Item
मध्यमReturn the first element while preserving its type.
function firstItem<T>(items: T[]): T | undefined {
return items[0];
}
const firstNumber = firstItem([4, 8, 15]);
const firstName = firstItem(["Ada", "Lin"]);