[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"content:legacy:page:\u002Finterviews\u002Ftypescript":3,"content:legacy:navigation":298,"content:legacy:surround:\u002Finterviews\u002Ftypescript":626},{"id":4,"title":5,"body":6,"description":285,"extension":286,"icon":287,"meta":288,"modifiedAt":289,"navigation":290,"path":291,"publishedAt":292,"seo":293,"sitemap":294,"stem":295,"updatedAt":296,"__hash__":297},"interviews\u002Finterviews\u002Ftypescript.md","TypeScript",{"type":7,"value":8,"toc":283},"minimark",[9,66,84,109,138,159,201,225,243,261],[10,11,12,36],"collapsible",{},[13,14,16],"template",{"v-slot:title":15},"",[17,18,19],"ol",{},[20,21,22,23,27,28,31,32,35],"li",{},"What is the difference between ",[24,25,26],"code",{},"any",", ",[24,29,30],{},"unknown",", and ",[24,33,34],{},"never","?",[13,37,38,56],{"v-slot:content":15},[39,40,41,46,51],"ul",{},[20,42,43,45],{},[24,44,26],{}," opts out of type checking and propagates unsafety.",[20,47,48,50],{},[24,49,30],{}," can hold any value, but must be narrowed before use.",[20,52,53,55],{},[24,54,34],{}," represents a value that cannot occur, such as the return type of a function that always throws or an exhausted union branch.",[57,58,59,60,62,63,65],"p",{},"Prefer ",[24,61,30],{}," at untrusted boundaries and use ",[24,64,34],{}," for exhaustive checks.",[10,67,68,76],{},[13,69,70],{"v-slot:title":15},[17,71,73],{"start":72},2,[20,74,75],{},"When should you use an interface versus a type alias?",[13,77,78,81],{"v-slot:content":15},[57,79,80],{},"Both can describe object shapes. Interfaces support declaration merging and are convenient for extendable public object contracts. Type aliases can also represent primitives, unions, tuples, conditional types, and mapped types.",[57,82,83],{},"Choose a consistent project convention; the important decision is whether a model should be open to extension or a closed composition.",[10,85,86,94],{},[13,87,88],{"v-slot:title":15},[17,89,91],{"start":90},3,[20,92,93],{},"How does control-flow narrowing work?",[13,95,96,106],{"v-slot:content":15},[57,97,98,99,27,102,105],{},"TypeScript refines a value based on runtime checks such as ",[24,100,101],{},"typeof",[24,103,104],{},"instanceof",", property existence, equality, truthiness, or a discriminant field. The narrowed type applies only where the compiler can prove the condition remains valid.",[57,107,108],{},"User-defined type predicates can package reusable checks, but their implementation must be trustworthy because the compiler accepts the predicate's claim.",[10,110,111,119],{},[13,112,113],{"v-slot:title":15},[17,114,116],{"start":115},4,[20,117,118],{},"Why are discriminated unions useful?",[13,120,121,132],{"v-slot:content":15},[57,122,123,124,127,128,131],{},"A discriminated union gives each variant a shared literal field such as ",[24,125,126],{},"status"," or ",[24,129,130],{},"kind",". Checking that field narrows the remaining properties safely.",[57,133,134,135,137],{},"They model state machines well because impossible combinations can be excluded—for example, a loading state cannot accidentally contain successful data. A ",[24,136,34],{}," assertion in the default branch makes switches exhaustive.",[10,139,140,148],{},[13,141,142],{"v-slot:title":15},[17,143,145],{"start":144},5,[20,146,147],{},"What problem do generics solve?",[13,149,150,156],{"v-slot:content":15},[57,151,152,153,155],{},"Generics express relationships between types while preserving information. A generic identity, collection helper, or API wrapper can return the same type it receives instead of falling back to a broad union or ",[24,154,26],{},".",[57,157,158],{},"Add constraints only for operations the implementation actually needs. Too many generic parameters can make an API harder to understand than a concrete type or overload.",[10,160,161,173],{},[13,162,163],{"v-slot:title":15},[17,164,166],{"start":165},6,[20,167,168,169,172],{},"Explain ",[24,170,171],{},"keyof",", indexed access types, and mapped types.",[13,174,175,198],{"v-slot:content":15},[39,176,177,186,195],{},[20,178,179,182,183,155],{},[24,180,181],{},"keyof T"," produces the union of known property keys of ",[24,184,185],{},"T",[20,187,188,191,192,155],{},[24,189,190],{},"T[K]"," looks up the value type for key ",[24,193,194],{},"K",[20,196,197],{},"A mapped type iterates over a key union to transform properties, for example making every property optional or readonly.",[57,199,200],{},"Together they allow utilities that stay synchronized with the source model.",[10,202,203,215],{},[13,204,205],{"v-slot:title":15},[17,206,208],{"start":207},7,[20,209,210,211,214],{},"What does the ",[24,212,213],{},"satisfies"," operator provide?",[13,216,217,222],{"v-slot:content":15},[57,218,219,221],{},[24,220,213],{}," checks that an expression is compatible with a target type without replacing the expression's more specific inferred type. It is useful for configuration objects where keys and values must be validated while literal information should remain available.",[57,223,224],{},"Unlike a type assertion, it performs a compatibility check and does not claim that an unchecked value has another type.",[10,226,227,235],{},[13,228,229],{"v-slot:title":15},[17,230,232],{"start":231},8,[20,233,234],{},"Why does TypeScript not replace runtime validation?",[13,236,237,240],{"v-slot:content":15},[57,238,239],{},"Type annotations are erased when JavaScript is emitted. Network responses, form values, local storage, environment variables, and parsed JSON can violate the declared types at runtime.",[57,241,242],{},"Validate external data at the boundary, then expose the validated result as a trusted domain type to the rest of the application.",[10,244,245,253],{},[13,246,247],{"v-slot:title":15},[17,248,250],{"start":249},9,[20,251,252],{},"What are the risks of type assertions and non-null assertions?",[13,254,255,258],{"v-slot:content":15},[57,256,257],{},"Assertions tell the compiler to trust the developer without adding a runtime check. They can hide a wrong model, race condition, missing DOM element, or incomplete API response.",[57,259,260],{},"Prefer narrowing, guards, defaults, and explicit error handling. Reserve assertions for cases where an invariant is enforced elsewhere and document that invariant close to the assertion.",[10,262,263,271],{},[13,264,265],{"v-slot:title":15},[17,266,268],{"start":267},10,[20,269,270],{},"How would you design a type-safe API result?",[13,272,273,280],{"v-slot:content":15},[57,274,275,276,279],{},"Use a discriminated union, for example a success variant containing ",[24,277,278],{},"data"," and an error variant containing a stable error code and message. Consumers must check the discriminant before accessing variant-specific fields.",[57,281,282],{},"Keep transport DTOs separate from domain models when parsing, normalization, dates, permissions, or version compatibility require transformation.",{"title":15,"searchDepth":72,"depth":72,"links":284},[],"TypeScript interview questions about modeling, narrowing, generics, inference, and safe API boundaries.","md","logos:typescript-icon",{},null,true,"\u002Finterviews\u002Ftypescript","2026-09-21",{"title":5,"description":285},{"loc":291,"lastmod":292},"interviews\u002Ftypescript","2026-09-21T22:49:35+07:00","YwDSrsvvkdImIWcWoiUeVE4dOFWgx3PF7Ka7UnJJIfM",[299,450,558,573],{"title":300,"icon":301,"path":302,"stem":303,"children":304,"page":315},"Posts","fluent-color:data-bar-vertical-ascending-24","\u002Fposts","posts",[305,316,334,360,370,384,394,404,414,440],{"title":306,"icon":307,"redirect":308,"path":309,"stem":310,"children":311,"page":315},"Database","material-icon-theme:database","\u002Fposts\u002Fdatabase\u002Freplication-strategy","\u002Fposts\u002Fdatabase","posts\u002Fdatabase",[312],{"title":313,"path":308,"stem":314,"icon":289},"Database Replication strategy in large systems","posts\u002Fdatabase\u002Freplication-strategy",false,{"title":317,"icon":318,"redirect":319,"path":320,"stem":321,"children":322,"page":315},"Docker","vscode-icons:file-type-docker2","\u002Fposts\u002Fdocker\u002Fdocker-commands","\u002Fposts\u002Fdocker","posts\u002Fdocker",[323,326,330],{"title":324,"path":319,"stem":325,"icon":289},"Docker commands essentials","posts\u002Fdocker\u002Fdocker-commands",{"title":327,"path":328,"stem":329,"icon":289},"Some useful Dockerfile templates","\u002Fposts\u002Fdocker\u002Fdockerfile-templates","posts\u002Fdocker\u002Fdockerfile-templates",{"title":331,"path":332,"stem":333,"icon":289},"Setup Docker environment on Windows","\u002Fposts\u002Fdocker\u002Fsetup-docker-on-window","posts\u002Fdocker\u002Fsetup-docker-on-window",{"title":335,"icon":336,"redirect":337,"path":338,"stem":339,"children":340,"page":315},"Git & GitHub","material-icon-theme:git","\u002Fposts\u002Fgit\u002Fbrightly-decorate-graph","\u002Fposts\u002Fgit","posts\u002Fgit",[341,344,348,352,356],{"title":342,"path":337,"stem":343,"icon":289},"Brightly decorate your GitHub Graph","posts\u002Fgit\u002Fbrightly-decorate-graph",{"title":345,"path":346,"stem":347,"icon":289},"Download a specific folder on GitHub repository","\u002Fposts\u002Fgit\u002Fdownload-specific-folder","posts\u002Fgit\u002Fdownload-specific-folder",{"title":349,"path":350,"stem":351,"icon":289},"Syncing Git Tags across to other repositories","\u002Fposts\u002Fgit\u002Fsyncing-tags-across-repositories","posts\u002Fgit\u002Fsyncing-tags-across-repositories",{"title":353,"path":354,"stem":355,"icon":289},"Unlocking GitHub Achievement badges","\u002Fposts\u002Fgit\u002Funlocking-achievement-badges","posts\u002Fgit\u002Funlocking-achievement-badges",{"title":357,"path":358,"stem":359,"icon":289},"Essential Git commands every developer should master","\u002Fposts\u002Fgit\u002Fuseful-commands-like-pro","posts\u002Fgit\u002Fuseful-commands-like-pro",{"title":361,"icon":362,"redirect":363,"path":364,"stem":365,"children":366,"page":315},"Golang","material-icon-theme:go","\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo","\u002Fposts\u002Fgolang","posts\u002Fgolang",[367],{"title":368,"path":363,"stem":369,"icon":289},"Optimizing Performance in Go Applications with PGO","posts\u002Fgolang\u002Foptimizing-performance-with-pgo",{"title":371,"icon":372,"redirect":373,"path":374,"stem":375,"children":376,"page":315},"JavaScript","vscode-icons:file-type-js","\u002Fposts\u002Fjavascript\u002F9-lines-of-tips","\u002Fposts\u002Fjavascript","posts\u002Fjavascript",[377,380],{"title":378,"path":373,"stem":379,"icon":289},"9 lines of JavaScript replace 50 lines of code","posts\u002Fjavascript\u002F9-lines-of-tips",{"title":381,"path":382,"stem":383,"icon":289},"Javascript Promises - Specific functions and use cases","\u002Fposts\u002Fjavascript\u002Fpromises-cheatsheet","posts\u002Fjavascript\u002Fpromises-cheatsheet",{"title":385,"icon":386,"redirect":387,"path":388,"stem":389,"children":390,"page":315},"Node","material-icon-theme:nodejs-alt","\u002Fposts\u002Fnodejs\u002Fevent-loop","\u002Fposts\u002Fnodejs","posts\u002Fnodejs",[391],{"title":392,"path":387,"stem":393,"icon":289},"Secret about Event Loop flow in Nodejs","posts\u002Fnodejs\u002Fevent-loop",{"title":395,"icon":396,"redirect":397,"path":398,"stem":399,"children":400,"page":315},"Nuxt","vscode-icons:file-type-nuxt","\u002Fposts\u002Fnuxt\u002Fenable-pwa-in-nuxt","\u002Fposts\u002Fnuxt","posts\u002Fnuxt",[401],{"title":402,"path":397,"stem":403,"icon":289},"Enable PWA and Service Worker in Nuxt","posts\u002Fnuxt\u002Fenable-pwa-in-nuxt",{"title":405,"icon":406,"redirect":407,"path":408,"stem":409,"children":410,"page":315},"Performance","emojione:rocket","\u002Fposts\u002Fperformance\u002Fbackground-image-injection-problem","\u002Fposts\u002Fperformance","posts\u002Fperformance",[411],{"title":412,"path":407,"stem":413,"icon":289},"Background-Image injection problem in UX","posts\u002Fperformance\u002Fbackground-image-injection-problem",{"title":415,"icon":416,"redirect":417,"path":418,"stem":419,"children":420,"page":315},"Tutorial","fluent-color:book-open-lightbulb-24","\u002Fposts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers","\u002Fposts\u002Ftutorial","posts\u002Ftutorial",[421,424,428,432,436],{"title":422,"path":417,"stem":423,"icon":289},"Classification and functionality of the servers","posts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers",{"title":425,"path":426,"stem":427,"icon":289},"What is the difference between localhost and 127.0.0.1?","\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1","posts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1",{"title":429,"path":430,"stem":431,"icon":289},"8 essential network protocols every programmer should know","\u002Fposts\u002Ftutorial\u002Fessential-network-protocols","posts\u002Ftutorial\u002Fessential-network-protocols",{"title":433,"path":434,"stem":435,"icon":289},"Pre rels in header link tag - SEO technique enhancement","\u002Fposts\u002Ftutorial\u002Fpre-rels-in-header-link-tag","posts\u002Ftutorial\u002Fpre-rels-in-header-link-tag",{"title":437,"path":438,"stem":439,"icon":289},"Better code with SOLID principles","\u002Fposts\u002Ftutorial\u002Fwhat-is-solid","posts\u002Ftutorial\u002Fwhat-is-solid",{"title":441,"icon":442,"redirect":443,"path":444,"stem":445,"children":446,"page":315},"UI\u002FUX","devicon:figma","\u002Fposts\u002Fuiux\u002Fcommon-button-mistake","\u002Fposts\u002Fuiux","posts\u002Fuiux",[447],{"title":448,"path":443,"stem":449,"icon":289},"Common Button Mistake in UI\u002FUX","posts\u002Fuiux\u002Fcommon-button-mistake",{"title":451,"icon":452,"path":453,"stem":454,"children":455,"page":315},"Cheatsheets","fluent-color:paw-16","\u002Fcheatsheets","cheatsheets",[456,461,466,469,474,477,482,486,491,496,501,506,511,516,520,524,529,534,538,543,548,553],{"title":457,"path":458,"stem":459,"icon":460},"Bash","\u002Fcheatsheets\u002Fbash","cheatsheets\u002Fbash","material-icon-theme:powershell",{"title":462,"path":463,"stem":464,"icon":465},"CSS","\u002Fcheatsheets\u002Fcss","cheatsheets\u002Fcss","vscode-icons:file-type-css2",{"title":317,"path":467,"stem":468,"icon":318},"\u002Fcheatsheets\u002Fdocker","cheatsheets\u002Fdocker",{"title":470,"path":471,"stem":472,"icon":473},"Git","\u002Fcheatsheets\u002Fgit","cheatsheets\u002Fgit","devicon:git",{"title":361,"path":475,"stem":476,"icon":362},"\u002Fcheatsheets\u002Fgo","cheatsheets\u002Fgo",{"title":478,"path":479,"stem":480,"icon":481},"HTML","\u002Fcheatsheets\u002Fhtml","cheatsheets\u002Fhtml","material-icon-theme:html",{"title":371,"path":483,"stem":484,"icon":485},"\u002Fcheatsheets\u002Fjavascript","cheatsheets\u002Fjavascript","material-icon-theme:javascript",{"title":487,"path":488,"stem":489,"icon":490},"Latex","\u002Fcheatsheets\u002Flatex","cheatsheets\u002Flatex","material-icon-theme:latexmk",{"title":492,"path":493,"stem":494,"icon":495},"Linux","\u002Fcheatsheets\u002Flinux","cheatsheets\u002Flinux","devicon:linux",{"title":497,"path":498,"stem":499,"icon":500},"Markdown","\u002Fcheatsheets\u002Fmarkdown","cheatsheets\u002Fmarkdown","material-icon-theme:markdown",{"title":502,"path":503,"stem":504,"icon":505},"Mongo","\u002Fcheatsheets\u002Fmongo","cheatsheets\u002Fmongo","devicon:mongodb",{"title":507,"path":508,"stem":509,"icon":510},"Nest","\u002Fcheatsheets\u002Fnest","cheatsheets\u002Fnest","material-icon-theme:nest",{"title":512,"path":513,"stem":514,"icon":515},"Next","\u002Fcheatsheets\u002Fnext","cheatsheets\u002Fnext","logos:nextjs-icon",{"title":385,"path":517,"stem":518,"icon":519},"\u002Fcheatsheets\u002Fnode","cheatsheets\u002Fnode","material-icon-theme:nodejs",{"title":395,"path":521,"stem":522,"icon":523},"\u002Fcheatsheets\u002Fnuxt","cheatsheets\u002Fnuxt","material-icon-theme:nuxt",{"title":525,"path":526,"stem":527,"icon":528},"React","\u002Fcheatsheets\u002Freact","cheatsheets\u002Freact","material-icon-theme:react",{"title":530,"path":531,"stem":532,"icon":533},"Redis","\u002Fcheatsheets\u002Fredis","cheatsheets\u002Fredis","vscode-icons:folder-type-redis-opened",{"title":535,"path":536,"stem":537,"icon":307},"SQL","\u002Fcheatsheets\u002Fsql","cheatsheets\u002Fsql",{"title":539,"path":540,"stem":541,"icon":542},"Typescript","\u002Fcheatsheets\u002Ftypescript","cheatsheets\u002Ftypescript","material-icon-theme:typescript",{"title":544,"path":545,"stem":546,"icon":547},"Vercel","\u002Fcheatsheets\u002Fvercel","cheatsheets\u002Fvercel","vscode-icons:file-type-light-vercel",{"title":549,"path":550,"stem":551,"icon":552},"Vue","\u002Fcheatsheets\u002Fvue","cheatsheets\u002Fvue","material-icon-theme:vue",{"title":554,"path":555,"stem":556,"icon":557},"Windows","\u002Fcheatsheets\u002Fwindow","cheatsheets\u002Fwindow","material-icon-theme:folder-windows",{"title":559,"icon":560,"path":561,"stem":562,"children":563,"page":315},"Prompts","fluent-color:bot-sparkle-24","\u002Fprompts","prompts",[564],{"title":565,"path":566,"stem":567,"children":568,"page":315},"Image Generation","\u002Fprompts\u002Fimage-generation","prompts\u002Fimage-generation",[569],{"title":570,"path":571,"stem":572,"icon":560},"Futuristic Cloud Workspace","\u002Fprompts\u002Fimage-generation\u002Ffuturistic-cloud-workspace","prompts\u002Fimage-generation\u002Ffuturistic-cloud-workspace",{"title":574,"icon":575,"path":576,"stem":577,"children":578,"page":315},"Interviews","lucide:messages-square","\u002Finterviews","interviews",[579,583,588,591,595,600,605,610,615,616,621],{"title":580,"path":581,"stem":582,"icon":575},"Behavioral Engineering","\u002Finterviews\u002Fbehavioral-engineering","interviews\u002Fbehavioral-engineering",{"title":584,"path":585,"stem":586,"icon":587},"DevOps and Cloud","\u002Finterviews\u002Fdevops-cloud","interviews\u002Fdevops-cloud","logos:docker-icon",{"title":478,"path":589,"stem":590,"icon":481},"\u002Finterviews\u002Fhtml","interviews\u002Fhtml",{"title":371,"path":592,"stem":593,"icon":594},"\u002Finterviews\u002Fjavascript","interviews\u002Fjavascript","logos:javascript",{"title":596,"path":597,"stem":598,"icon":599},"Node.js and API Design","\u002Finterviews\u002Fnodejs-api","interviews\u002Fnodejs-api","logos:nodejs-icon",{"title":601,"path":602,"stem":603,"icon":604},"Software Testing","\u002Finterviews\u002Fsoftware-testing","interviews\u002Fsoftware-testing","lucide:flask-conical",{"title":606,"path":607,"stem":608,"icon":609},"SQL and Databases","\u002Finterviews\u002Fsql-databases","interviews\u002Fsql-databases","lucide:database",{"title":611,"path":612,"stem":613,"icon":614},"System Design","\u002Finterviews\u002Fsystem-design","interviews\u002Fsystem-design","lucide:network",{"title":5,"path":291,"stem":295,"icon":287},{"title":617,"path":618,"stem":619,"icon":620},"Vue and Nuxt","\u002Finterviews\u002Fvue-nuxt","interviews\u002Fvue-nuxt","logos:nuxt-icon",{"title":622,"path":623,"stem":624,"icon":625},"Web Security","\u002Finterviews\u002Fweb-security","interviews\u002Fweb-security","lucide:shield-check",[627,628],{"title":611,"path":612,"stem":613,"children":-1},{"title":617,"path":618,"stem":619,"children":-1}]