Modules aur Standard Library
TypeScript code aksar multiple files mein split hota hai, import aur export se juda hua. Yeh compiler ek waqt mein sirf ek hi file chalata hai, isliye multi-file imports yahan seedha dikhaye nahi ja sakte, lekin is lesson mein baaki sab kuch bilkul waise hi chalta hai jaise dikhaya gaya hai.
Utility types — maujooda types se naye types banana
TypeScript kuch built-in utility types ke sath aata hai jo ek maujooda type ko tabdeel karte hain. Partial<T> T ki har property ko optional bana deta hai — kisi update function jaisi cheez ke liye kaam aata hai jahan aap sirf woh fields dete hain jo tabdeel ho rahe hain.
interface Product {
id: number;
name: string;
price: number;
}
function updateProduct(product: Product, changes: Partial<Product>): Product {
return { ...product, ...changes };
}
const original: Product = { id: 1, name: "Keyboard", price: 50 };
const updated = updateProduct(original, { price: 45 });
console.log(updated);{ id: 1, name: 'Keyboard', price: 45 }Pick<T, Keys> T se sirf listed properties ke sath ek naya type banata hai; Record<Keys, Type> ek object type banata hai jahan Keys ki har key same value type ko map karti hai. Dono hi ek naya, precise type ek aise type se derive karne ke tareeqe hain jise aap pehle se define kar chuke hain, use haath se likhne ke bajaye.
interface Product {
id: number;
name: string;
price: number;
}
type ProductSummary = Pick<Product, "id" | "name">;
const summary: ProductSummary = { id: 1, name: "Keyboard" };
console.log(summary);{ id: 1, name: 'Keyboard' }Bas itna hi hai JavaScript ke upar TypeScript ke type system ka core. Yahan se, best agla qadam hai mashq — koi chhota sa idea chuno aur use banao, types par inhisar karte hue jo raaste mein mistakes pakrein.