🎤 टॉप 81 Interview Questions
ये सबसे common Java interview questions हैं — tap करके answer खोलो।
Microsoft dwara banaya gaya, JavaScript ka ek superset hai — STATIC types add karta hai. Compiler (tsc) ise plain JavaScript mein transpile karta hai.
NAHI — types sirf COMPILE-TIME PAR exist karte hain, RUNTIME PAR completely "erased" ho jaate hain.
JavaScript dynamically typed hai — types runtime PAR decide hote hain. TypeScript statically typed hai — types compile-time PAR check hote hain.
Ek existing JavaScript project mein file-by-file TypeScript introduce kiya ja sakta hai, poore project ko ek saath rewrite kiye bina.
: type syntax se explicitly type declare karna — variables, function parameters, aur return types PAR use hote hain.
TypeScript khud hi type "guess" kar leta hai context (jaise initial value) se — explicit annotation ki zaroorat nahi hoti.
Parameters, call hone se pehle unke type ka koi context nahi hota — isliye explicit annotations chahiye hoti hain.
Function parameters PAR hamesha explicit annotations. Variables ke liye, jab possible ho, TypeScript ko infer karne do.
Ek hi type hai — JavaScript ki tarah, saare numbers internally floating-point hote hain, alag int/float types nahi hain.
Array, same type ki multiple values ka collection hai. Tuple, fixed-length array hai jaha har position ka specific type hota hai.
Type checking ko COMPLETELY disable kar deta hai — TypeScript ke fayde kho jaate hain, isliye overuse avoid karna chahiye.
unknown mein, value use karne se pehle type check (narrowing) karna zaroori hai — any mein koi checking nahi hoti.
Ek value jo kabhi occur hi nahi hoti — jaise ek function jo hamesha throw karta hai (kabhi normally return nahi karta).
Ek value ko multiple possible types mein se ek hone deta hai — jaise string | number.
Multiple types ko combine karta hai — resulting type saare combined types ki properties rakhta hai (A & B).
API responses ke liye "loading" | "success" | "error" jaise states represent karne ke liye.
Ek object ki shape define karta hai — property naam aur types specify kiye jaate hain.
Agar ek object ki shape interface ko match karti hai, woh valid hai — chahe explicitly "implements" keyword se declare na kiya gaya ho.
Ek existing type ko ek naya naam deta hai — primitives, union types, ya object shapes ke liye use ho sakta hai.
Interfaces "declaration merging" support karte hain (same naam se multiple baar define karne par merge ho jaate hain). Type aliases ye nahi kar sakte.
Ek interface, dusre interface se extend hoti hai — child interface, parent ki saari properties inherit karta hai.
Haan — interface Manager extends Employee, Person, dono se ek saath extend kar sakta hai.
Property ko OPTIONAL banata hai — woh present ho sakti hai ya nahi bhi ho sakti.
Ek property ko initialization ke baad modify hone se rokta hai.
Parameters ko infer nahi kiya ja sakta — explicit annotations zaroori hain.
Ek function ya type ko multiple types ke saath kaam karne dete hain, bina type safety khoye — <T> ek "type parameter" hai.
Generics, type relationships maintain karte hain (jaise input aur output ka same type). any, type safety completely khota hai.
Ek generic type ko restrict karta hai — sirf wohi types allowed hain jo ek specific shape match karte hain.
Saari properties ko optional banata hai — update functions ke liye common hai.
Pick, sirf specific properties select karta hai. Omit, specific properties ko exclude karta hai.
Ek object type jisme har key type K ki hai aur har value type V ki hai — dictionary-jaisa structure.
Ek hi function ke multiple type signatures — different argument types/counts ke liye different return types specify karne ke liye.
Union types (parameter: TypeA | TypeB) — most cases mein simpler aur equally effective solution hain.
Same hi hain, lekin har property aur method ka type explicitly specified hota hai.
Constructor parameters PAR access modifiers (public, private) likhne se automatically ek property declare aur assign ho jaati hai.
public (default) = har jagah se accessible. private = sirf usi class ke andar se. protected = class + subclasses se accessible.
TypeScript ka private, sirf compile-time checking hai. JavaScript ka native #private, actual runtime privacy deta hai.
Ek "template blueprint" hai jise directly instantiate nahi kiya ja sakta — sirf subclasses extend karke complete karti hain.
Sirf signature — implementation nahi. Subclasses ko implement karna zaroori hai.
Class explicitly declare karti hai ki woh ek interface ko follow karegi — TypeScript verify karta hai ki saare required members implemented hain.
Sirf ek — single inheritance. Lekin multiple interfaces implement kar sakti hai.
Ek existing type ke keys PAR iterate karke ek naya type banate hain — [K in keyof T] syntax se likhe jaate hain.
Mapped types — Partial, Readonly, jaise utility types internally mapped types se hi implement hote hain.
"Type-level if-else" hai — T extends U ? X : Y syntax use karta hai.
Conditional types ke andar ek type ko "extract" karne ke liye use hota hai — jaise ek function ke return type ko extract karna.
Template literal string syntax ko type level PAR use karte hain — jaise `hello-${string}`, koi bhi string match karega jo "hello-" se shuru hoti hai.
Ek broad type (jaise string | number) ko check karke ek specific type tak "narrow" karna.
typeof se primitive types narrow kiye jaate hain. instanceof se class instances ko narrow kiya jaata hai.
Ek function jo (value is Type) syntax use karta hai — complex narrowing logic ko reusable banata hai.
Explicitly batata hai ki ek import sirf type-checking ke liye hai — runtime JavaScript mein ye import completely remove ho jaata hai.
Declaration files — sirf type information rakhti hain, koi actual implementation code nahi.
JavaScript libraries ke liye TYPES provide karte hain jo khud TypeScript mein nahi likhi gayi — DefinitelyTyped project dwara maintain kiye jaate hain.
TypeScript ko batata hai ki ek variable/function/module runtime PAR kahi define hai — TypeScript iski actual implementation nahi dekh sakta.
Global variables jo third-party scripts (jaise CDN se loaded library) se aate hain, unke liye.
Related code ko organize karne ke liye — ES Modules (import/export) ke aane se pehle ye main organization tool tha.
ES Modules (import/export) — namespaces rarely use hote hain naye code mein.
TypeScript compiler ki configuration file — target, module, strict jaise options compilerOptions mein hote hain.
TypeScript compiler — .ts files ko .js mein compile karta hai.
Manually compile kiye bina, TypeScript ko directly run karne deta hai — development ke liye useful.
Multiple strictness flags (strictNullChecks, noImplicitAny, etc.) ek saath enable karta hai.
"Cannot read property of undefined" jaisi errors ko compile-time PAR hi pakadta hai.
TypeScript, types verify karta hai. ESLint, code quality aur style consistency enforce karta hai.
ESLint ko TypeScript syntax samajhne ki ability deta hai — type-aware linting rules ke liye.
Ek interface se — jaise interface ButtonProps { label: string; onClick: () => void; }.
Jab initial value (jaise null) se TypeScript poora type infer nahi kar sakta — useState<User | null>(null).
Node.js ke built-in APIs (fs, path, process) ke liye types — process.env aur __dirname jaise globals ke baare mein.
string | undefined — explicit checks ya default values (||) zaroori hain undefined handle karne ke liye.
Request, Response, aur NextFunction jaise types — route handlers ko properly type kiya ja sakta hai.
req.body aur req.params ko bhi TYPE karta hai — bina iske generic string type ki hoti hain.
TypeScript aur JavaScript files ek saath exist kar sakti hain — migration file-by-file ki ja sakti hai.
"Most used" files se (jaise shared utilities) — maximum type-safety benefit early milta hai kyunki woh files har jagah import hoti hain.
Ek pattern jaha har type mein ek common "tag" property hai (jaise kind), jisse TypeScript easily narrow kar sakta hai ki kaun sa specific type hai.
Ek interface define karne deti hai jisme property names pehle se pata nahi hain — jaise { [key: string]: number }.
Ek function type ke return type ko extract karta hai.
Class ke level PAR define hote hain, individual instances PAR nahi — saari instances ke beech shared hote hain.
Ek function banate hain jo throw karta hai agar ek condition false hai — TypeScript ise ek type assertion ki tarah treat karta hai function call ke baad.
Existing modules ko "augment" (extend) kiya ja sakta hai — jaise Express ki Request interface mein ek custom property add karna.
.js.map files generate karte hain — debugger ko compiled JavaScript ko original TypeScript source se map karne dete hain.
Synthetic events — jaise React.MouseEvent<HTMLButtonElement>, properly typed event deta hai.
Compilation step add karna, iteration speed ko slow kar sakta hai chhote experiments ke liye.
Ek variable ko specific string/number VALUES tak restrict karte hain — jaise let direction: "up" | "down", generic string type ki jagah.