[{"data":1,"prerenderedAt":6433},["ShallowReactive",2],{"home-featured-articles":3,"privacy-policy":6171},[4,2335,4578],{"id":5,"title":6,"body":7,"date":2317,"description":13,"draft":2318,"extension":2319,"featured":1031,"image":2320,"meta":2323,"navigation":1031,"path":2324,"seo":2325,"stem":2326,"tags":2327,"updatedAt":2333,"__hash__":2334},"blog\u002Fblog\u002F10-typescript-practices-that-make-your-codebase-better.md","10 TypeScript Practices That Make Your Codebase Better",{"type":8,"value":9,"toc":2299},"minimark",[10,14,17,26,36,39,42,45,48,76,79,82,85,88,91,96,99,102,105,108,189,192,224,227,253,256,283,286,310,313,316,359,362,365,368,371,375,378,381,384,467,470,473,476,479,482,514,517,520,523,526,530,533,556,559,562,610,613,715,718,748,751,754,757,760,763,766,774,777,815,818,911,914,917,955,961,964,970,1127,1130,1133,1136,1144,1147,1150,1152,1192,1195,1210,1213,1216,1251,1254,1257,1274,1277,1280,1288,1291,1331,1334,1337,1340,1343,1379,1382,1446,1449,1452,1455,1472,1475,1478,1482,1484,1529,1532,1535,1538,1595,1598,1684,1687,1690,1693,1696,1699,1703,1710,1713,1716,1719,1722,1727,1730,1733,1736,1744,1747,1750,1753,1756,1760,1763,1766,1769,1772,1775,1780,1783,1786,1789,1792,1935,1938,1941,1944,1947,1950,1953,1956,1959,1962,1966,1969,1972,2033,2036,2039,2041,2044,2047,2061,2064,2067,2070,2074,2077,2080,2083,2086,2158,2161,2164,2167,2170,2173,2176,2179,2182,2185,2189,2192,2243,2246,2250,2253,2256,2259,2262,2265,2268,2271,2274,2277,2280,2283,2286,2289,2292,2295],[11,12,13],"p",{},"Practical patterns for writing TypeScript that remains readable, maintainable, and useful as your application grows.",[11,15,16],{},"This is Part 2 of a two-part series on writing better TypeScript.",[11,18,19,20,25],{},"In ",[21,22,24],"a",{"href":23},"\u002Fblog\u002Fyou-know-typescript-but-do-you-know-how-to-model-your-code-with-it","Part 1",", we looked at how to model domains and make invalid states harder to represent. This article focuses on the practical patterns that keep TypeScript code maintainable as the codebase grows.",[11,27,28,29,35],{},"Originally published on ",[21,30,34],{"href":31,"rel":32},"https:\u002F\u002Fakshattriv.medium.com\u002F10-typescript-practices-that-make-your-codebase-better-1e458fb3275e",[33],"nofollow","Medium",".",[11,37,38],{},"Knowing TypeScript syntax is one thing.",[11,40,41],{},"Using TypeScript well in a large codebase is another.",[11,43,44],{},"Once an application grows beyond a few thousand lines, the biggest TypeScript problems usually aren’t caused by not knowing what a generic is.",[11,46,47],{},"They’re caused by things like:",[49,50,51,55,58,61,64,67,70,73],"ul",{},[52,53,54],"li",{},"abstractions that are too clever",[52,56,57],{},"types that are too broad",[52,59,60],{},"assertions everywhere",[52,62,63],{},"duplicated contracts",[52,65,66],{},"unreadable generics",[52,68,69],{},"functions with ambiguous APIs",[52,71,72],{},"types scattered across the project",[52,74,75],{},"compiler settings that aren’t taken seriously",[11,77,78],{},"In a small project, these problems might be harmless.",[11,80,81],{},"In a large application with dozens of developers, they compound.",[11,83,84],{},"A type that is slightly confusing today becomes technical debt six months later.",[11,86,87],{},"So this article isn’t about obscure TypeScript tricks.",[11,89,90],{},"It’s about practical decisions that make TypeScript code easier to understand and maintain.",[92,93,95],"h2",{"id":94},"_1-use-generics-to-express-relationships","1. Use Generics to Express Relationships",[11,97,98],{},"Generics are often introduced as a way to make functions reusable.",[11,100,101],{},"That’s true.",[11,103,104],{},"But their more important purpose is expressing relationships between types.",[11,106,107],{},"Consider:",[109,110,115],"pre",{"className":111,"code":112,"language":113,"meta":114,"style":114},"language-ts shiki shiki-themes github-light github-dark","function getFirst\u003CT>(items: T[]): T | undefined {\n  return items[0]\n}\n","ts","",[116,117,118,168,183],"code",{"__ignoreMap":114},[119,120,123,127,131,135,138,141,145,148,151,154,156,158,161,165],"span",{"class":121,"line":122},"line",1,[119,124,126],{"class":125},"szBVR","function",[119,128,130],{"class":129},"sScJk"," getFirst",[119,132,134],{"class":133},"sVt8B","\u003C",[119,136,137],{"class":129},"T",[119,139,140],{"class":133},">(",[119,142,144],{"class":143},"s4XuR","items",[119,146,147],{"class":125},":",[119,149,150],{"class":129}," T",[119,152,153],{"class":133},"[])",[119,155,147],{"class":125},[119,157,150],{"class":129},[119,159,160],{"class":125}," |",[119,162,164],{"class":163},"sj4cs"," undefined",[119,166,167],{"class":133}," {\n",[119,169,171,174,177,180],{"class":121,"line":170},2,[119,172,173],{"class":125},"  return",[119,175,176],{"class":133}," items[",[119,178,179],{"class":163},"0",[119,181,182],{"class":133},"]\n",[119,184,186],{"class":121,"line":185},3,[119,187,188],{"class":133},"}\n",[11,190,191],{},"If you pass:",[109,193,195],{"className":111,"code":194,"language":113,"meta":114,"style":114},"const users: User[] = [...]\n",[116,196,197],{"__ignoreMap":114},[119,198,199,202,205,207,210,213,216,219,222],{"class":121,"line":122},[119,200,201],{"class":125},"const",[119,203,204],{"class":163}," users",[119,206,147],{"class":125},[119,208,209],{"class":129}," User",[119,211,212],{"class":133},"[] ",[119,214,215],{"class":125},"=",[119,217,218],{"class":133}," [",[119,220,221],{"class":125},"...",[119,223,182],{"class":133},[11,225,226],{},"TypeScript knows:",[109,228,230],{"className":111,"code":229,"language":113,"meta":114,"style":114},"const user = getFirst(users)\n\u002F\u002F User | undefined\n",[116,231,232,247],{"__ignoreMap":114},[119,233,234,236,239,242,244],{"class":121,"line":122},[119,235,201],{"class":125},[119,237,238],{"class":163}," user",[119,240,241],{"class":125}," =",[119,243,130],{"class":129},[119,245,246],{"class":133},"(users)\n",[119,248,249],{"class":121,"line":170},[119,250,252],{"class":251},"sJ8bj","\u002F\u002F User | undefined\n",[11,254,255],{},"And if you pass:",[109,257,259],{"className":111,"code":258,"language":113,"meta":114,"style":114},"const products: Product[] = [...]\n",[116,260,261],{"__ignoreMap":114},[119,262,263,265,268,270,273,275,277,279,281],{"class":121,"line":122},[119,264,201],{"class":125},[119,266,267],{"class":163}," products",[119,269,147],{"class":125},[119,271,272],{"class":129}," Product",[119,274,212],{"class":133},[119,276,215],{"class":125},[119,278,218],{"class":133},[119,280,221],{"class":125},[119,282,182],{"class":133},[11,284,285],{},"you get:",[109,287,289],{"className":111,"code":288,"language":113,"meta":114,"style":114},"const product = getFirst(products)\n\u002F\u002F Product | undefined\n",[116,290,291,305],{"__ignoreMap":114},[119,292,293,295,298,300,302],{"class":121,"line":122},[119,294,201],{"class":125},[119,296,297],{"class":163}," product",[119,299,241],{"class":125},[119,301,130],{"class":129},[119,303,304],{"class":133},"(products)\n",[119,306,307],{"class":121,"line":170},[119,308,309],{"class":251},"\u002F\u002F Product | undefined\n",[11,311,312],{},"The generic preserves the relationship between input and output.",[11,314,315],{},"Compare that with:",[109,317,319],{"className":111,"code":318,"language":113,"meta":114,"style":114},"function getFirst(items: unknown[]): unknown {\n  return items[0]\n}\n",[116,320,321,345,355],{"__ignoreMap":114},[119,322,323,325,327,330,332,334,337,339,341,343],{"class":121,"line":122},[119,324,126],{"class":125},[119,326,130],{"class":129},[119,328,329],{"class":133},"(",[119,331,144],{"class":143},[119,333,147],{"class":125},[119,335,336],{"class":163}," unknown",[119,338,153],{"class":133},[119,340,147],{"class":125},[119,342,336],{"class":163},[119,344,167],{"class":133},[119,346,347,349,351,353],{"class":121,"line":170},[119,348,173],{"class":125},[119,350,176],{"class":133},[119,352,179],{"class":163},[119,354,182],{"class":133},[119,356,357],{"class":121,"line":185},[119,358,188],{"class":133},[11,360,361],{},"Now you’ve lost that relationship.",[11,363,364],{},"A useful question when writing a generic is:",[11,366,367],{},"What relationship between these types am I trying to preserve?",[11,369,370],{},"If you can’t answer that, you might not need a generic.",[92,372,374],{"id":373},"_2-dont-turn-everything-into-a-generic","2. Don’t Turn Everything Into a Generic",[11,376,377],{},"Generics are powerful.",[11,379,380],{},"That’s exactly why they are easy to overuse.",[11,382,383],{},"You can write something like:",[109,385,387],{"className":111,"code":386,"language":113,"meta":114,"style":114},"function processData\u003C\n  T extends Record\u003Cstring, unknown>,\n  K extends keyof T,\n  R extends ...,\n>(...) {\n  \u002F\u002F ...\n}\n",[116,388,389,399,424,439,450,456,462],{"__ignoreMap":114},[119,390,391,393,396],{"class":121,"line":122},[119,392,126],{"class":125},[119,394,395],{"class":129}," processData",[119,397,398],{"class":133},"\u003C\n",[119,400,401,404,407,410,412,415,418,421],{"class":121,"line":170},[119,402,403],{"class":129},"  T",[119,405,406],{"class":125}," extends",[119,408,409],{"class":129}," Record",[119,411,134],{"class":133},[119,413,414],{"class":163},"string",[119,416,417],{"class":133},", ",[119,419,420],{"class":163},"unknown",[119,422,423],{"class":133},">,\n",[119,425,426,429,431,434,436],{"class":121,"line":185},[119,427,428],{"class":129},"  K",[119,430,406],{"class":125},[119,432,433],{"class":125}," keyof",[119,435,150],{"class":129},[119,437,438],{"class":133},",\n",[119,440,442,445,447],{"class":121,"line":441},4,[119,443,444],{"class":129},"  R",[119,446,406],{"class":125},[119,448,449],{"class":133}," ...,\n",[119,451,453],{"class":121,"line":452},5,[119,454,455],{"class":133},">(...) {\n",[119,457,459],{"class":121,"line":458},6,[119,460,461],{"class":251},"  \u002F\u002F ...\n",[119,463,465],{"class":121,"line":464},7,[119,466,188],{"class":133},[11,468,469],{},"And feel pretty good about yourself.",[11,471,472],{},"Then someone else opens the file six months later.",[11,474,475],{},"They feel something else.",[11,477,478],{},"Complex generics introduce cognitive overhead.",[11,480,481],{},"If a simple function communicates the intent:",[109,483,485],{"className":111,"code":484,"language":113,"meta":114,"style":114},"function processUser(user: User) {\n  \u002F\u002F ...\n}\n",[116,486,487,506,510],{"__ignoreMap":114},[119,488,489,491,494,496,499,501,503],{"class":121,"line":122},[119,490,126],{"class":125},[119,492,493],{"class":129}," processUser",[119,495,329],{"class":133},[119,497,498],{"class":143},"user",[119,500,147],{"class":125},[119,502,209],{"class":129},[119,504,505],{"class":133},") {\n",[119,507,508],{"class":121,"line":170},[119,509,461],{"class":251},[119,511,512],{"class":121,"line":185},[119,513,188],{"class":133},[11,515,516],{},"then use the simple function.",[11,518,519],{},"The goal isn’t to demonstrate how much TypeScript you know.",[11,521,522],{},"The goal is to make the code easier to understand.",[11,524,525],{},"Use generics when they express a meaningful relationship—not simply because they can.",[92,527,529],{"id":528},"_3-prefer-type-narrowing-over-casting","3. Prefer Type Narrowing Over Casting",[11,531,532],{},"This is tempting:",[109,534,536],{"className":111,"code":535,"language":113,"meta":114,"style":114},"const value = something as string\n",[116,537,538],{"__ignoreMap":114},[119,539,540,542,545,547,550,553],{"class":121,"line":122},[119,541,201],{"class":125},[119,543,544],{"class":163}," value",[119,546,241],{"class":125},[119,548,549],{"class":133}," something ",[119,551,552],{"class":125},"as",[119,554,555],{"class":163}," string\n",[11,557,558],{},"But you’re bypassing the compiler’s uncertainty.",[11,560,561],{},"Instead, narrow the value:",[109,563,565],{"className":111,"code":564,"language":113,"meta":114,"style":114},"if (typeof something === 'string') {\n  console.log(something.toUpperCase())\n}\n",[116,566,567,589,606],{"__ignoreMap":114},[119,568,569,572,575,578,580,583,587],{"class":121,"line":122},[119,570,571],{"class":125},"if",[119,573,574],{"class":133}," (",[119,576,577],{"class":125},"typeof",[119,579,549],{"class":133},[119,581,582],{"class":125},"===",[119,584,586],{"class":585},"sZZnC"," 'string'",[119,588,505],{"class":133},[119,590,591,594,597,600,603],{"class":121,"line":170},[119,592,593],{"class":133},"  console.",[119,595,596],{"class":129},"log",[119,598,599],{"class":133},"(something.",[119,601,602],{"class":129},"toUpperCase",[119,604,605],{"class":133},"())\n",[119,607,608],{"class":121,"line":185},[119,609,188],{"class":133},[11,611,612],{},"For objects, create a type guard when appropriate:",[109,614,616],{"className":111,"code":615,"language":113,"meta":114,"style":114},"function isUser(value: unknown): value is User {\n  return (\n    typeof value === 'object'\n    && value !== null\n    && 'id' in value\n    && 'name' in value\n  )\n}\n",[116,617,618,648,655,668,681,694,705,710],{"__ignoreMap":114},[119,619,620,622,625,627,630,632,634,637,639,641,644,646],{"class":121,"line":122},[119,621,126],{"class":125},[119,623,624],{"class":129}," isUser",[119,626,329],{"class":133},[119,628,629],{"class":143},"value",[119,631,147],{"class":125},[119,633,336],{"class":163},[119,635,636],{"class":133},")",[119,638,147],{"class":125},[119,640,544],{"class":143},[119,642,643],{"class":125}," is",[119,645,209],{"class":129},[119,647,167],{"class":133},[119,649,650,652],{"class":121,"line":170},[119,651,173],{"class":125},[119,653,654],{"class":133}," (\n",[119,656,657,660,663,665],{"class":121,"line":185},[119,658,659],{"class":125},"    typeof",[119,661,662],{"class":133}," value ",[119,664,582],{"class":125},[119,666,667],{"class":585}," 'object'\n",[119,669,670,673,675,678],{"class":121,"line":441},[119,671,672],{"class":125},"    &&",[119,674,662],{"class":133},[119,676,677],{"class":125},"!==",[119,679,680],{"class":163}," null\n",[119,682,683,685,688,691],{"class":121,"line":452},[119,684,672],{"class":125},[119,686,687],{"class":585}," 'id'",[119,689,690],{"class":125}," in",[119,692,693],{"class":143}," value\n",[119,695,696,698,701,703],{"class":121,"line":458},[119,697,672],{"class":125},[119,699,700],{"class":585}," 'name'",[119,702,690],{"class":125},[119,704,693],{"class":143},[119,706,707],{"class":121,"line":464},[119,708,709],{"class":133},"  )\n",[119,711,713],{"class":121,"line":712},8,[119,714,188],{"class":133},[11,716,717],{},"Then:",[109,719,721],{"className":111,"code":720,"language":113,"meta":114,"style":114},"if (isUser(value)) {\n  console.log(value.name)\n}\n",[116,722,723,735,744],{"__ignoreMap":114},[119,724,725,727,729,732],{"class":121,"line":122},[119,726,571],{"class":125},[119,728,574],{"class":133},[119,730,731],{"class":129},"isUser",[119,733,734],{"class":133},"(value)) {\n",[119,736,737,739,741],{"class":121,"line":170},[119,738,593],{"class":133},[119,740,596],{"class":129},[119,742,743],{"class":133},"(value.name)\n",[119,745,746],{"class":121,"line":185},[119,747,188],{"class":133},[11,749,750],{},"The distinction is important:",[11,752,753],{},"Casting says:",[11,755,756],{},"“Trust me.”",[11,758,759],{},"Narrowing says:",[11,761,762],{},"“Here’s why this value is safe to treat this way.”",[11,764,765],{},"The second approach gives the type system something to work with.",[92,767,769,770,773],{"id":768},"_4-use-never-to-catch-incomplete-logic","4. Use ",[116,771,772],{},"never"," to Catch Incomplete Logic",[11,775,776],{},"Imagine:",[109,778,780],{"className":111,"code":779,"language":113,"meta":114,"style":114},"type Status =\n  | 'pending'\n  | 'approved'\n  | 'rejected'\n",[116,781,782,793,801,808],{"__ignoreMap":114},[119,783,784,787,790],{"class":121,"line":122},[119,785,786],{"class":125},"type",[119,788,789],{"class":129}," Status",[119,791,792],{"class":125}," =\n",[119,794,795,798],{"class":121,"line":170},[119,796,797],{"class":125},"  |",[119,799,800],{"class":585}," 'pending'\n",[119,802,803,805],{"class":121,"line":185},[119,804,797],{"class":125},[119,806,807],{"class":585}," 'approved'\n",[119,809,810,812],{"class":121,"line":441},[119,811,797],{"class":125},[119,813,814],{"class":585}," 'rejected'\n",[11,816,817],{},"You might write:",[109,819,821],{"className":111,"code":820,"language":113,"meta":114,"style":114},"function getLabel(status: Status) {\n  switch (status) {\n    case 'pending':\n      return 'Pending'\n    case 'approved':\n      return 'Approved'\n    case 'rejected':\n      return 'Rejected'\n  }\n}\n",[116,822,823,841,849,860,868,877,884,893,900,906],{"__ignoreMap":114},[119,824,825,827,830,832,835,837,839],{"class":121,"line":122},[119,826,126],{"class":125},[119,828,829],{"class":129}," getLabel",[119,831,329],{"class":133},[119,833,834],{"class":143},"status",[119,836,147],{"class":125},[119,838,789],{"class":129},[119,840,505],{"class":133},[119,842,843,846],{"class":121,"line":170},[119,844,845],{"class":125},"  switch",[119,847,848],{"class":133}," (status) {\n",[119,850,851,854,857],{"class":121,"line":185},[119,852,853],{"class":125},"    case",[119,855,856],{"class":585}," 'pending'",[119,858,859],{"class":133},":\n",[119,861,862,865],{"class":121,"line":441},[119,863,864],{"class":125},"      return",[119,866,867],{"class":585}," 'Pending'\n",[119,869,870,872,875],{"class":121,"line":452},[119,871,853],{"class":125},[119,873,874],{"class":585}," 'approved'",[119,876,859],{"class":133},[119,878,879,881],{"class":121,"line":458},[119,880,864],{"class":125},[119,882,883],{"class":585}," 'Approved'\n",[119,885,886,888,891],{"class":121,"line":464},[119,887,853],{"class":125},[119,889,890],{"class":585}," 'rejected'",[119,892,859],{"class":133},[119,894,895,897],{"class":121,"line":712},[119,896,864],{"class":125},[119,898,899],{"class":585}," 'Rejected'\n",[119,901,903],{"class":121,"line":902},9,[119,904,905],{"class":133},"  }\n",[119,907,909],{"class":121,"line":908},10,[119,910,188],{"class":133},[11,912,913],{},"That’s fine.",[11,915,916],{},"But what happens six months later when someone adds:",[109,918,920],{"className":111,"code":919,"language":113,"meta":114,"style":114},"type Status =\n  | 'pending'\n  | 'approved'\n  | 'rejected'\n  | 'cancelled'\n",[116,921,922,930,936,942,948],{"__ignoreMap":114},[119,923,924,926,928],{"class":121,"line":122},[119,925,786],{"class":125},[119,927,789],{"class":129},[119,929,792],{"class":125},[119,931,932,934],{"class":121,"line":170},[119,933,797],{"class":125},[119,935,800],{"class":585},[119,937,938,940],{"class":121,"line":185},[119,939,797],{"class":125},[119,941,807],{"class":585},[119,943,944,946],{"class":121,"line":441},[119,945,797],{"class":125},[119,947,814],{"class":585},[119,949,950,952],{"class":121,"line":452},[119,951,797],{"class":125},[119,953,954],{"class":585}," 'cancelled'\n",[11,956,957,958,35],{},"There might be dozens of places that depend on ",[116,959,960],{},"Status",[11,962,963],{},"You want the compiler to tell you where your assumptions are incomplete.",[11,965,966,967,969],{},"That’s where ",[116,968,772],{}," can help:",[109,971,973],{"className":111,"code":972,"language":113,"meta":114,"style":114},"function assertNever(value: never): never {\n  throw new Error(`Unhandled value: ${value}`)\n}\n\nfunction getLabel(status: Status) {\n  switch (status) {\n    case 'pending':\n      return 'Pending'\n    case 'approved':\n      return 'Approved'\n    case 'rejected':\n      return 'Rejected'\n    default:\n      return assertNever(status)\n  }\n}\n",[116,974,975,999,1023,1027,1033,1049,1055,1063,1069,1077,1083,1092,1099,1107,1117,1122],{"__ignoreMap":114},[119,976,977,979,982,984,986,988,991,993,995,997],{"class":121,"line":122},[119,978,126],{"class":125},[119,980,981],{"class":129}," assertNever",[119,983,329],{"class":133},[119,985,629],{"class":143},[119,987,147],{"class":125},[119,989,990],{"class":163}," never",[119,992,636],{"class":133},[119,994,147],{"class":125},[119,996,990],{"class":163},[119,998,167],{"class":133},[119,1000,1001,1004,1007,1010,1012,1015,1017,1020],{"class":121,"line":170},[119,1002,1003],{"class":125},"  throw",[119,1005,1006],{"class":125}," new",[119,1008,1009],{"class":129}," Error",[119,1011,329],{"class":133},[119,1013,1014],{"class":585},"`Unhandled value: ${",[119,1016,629],{"class":133},[119,1018,1019],{"class":585},"}`",[119,1021,1022],{"class":133},")\n",[119,1024,1025],{"class":121,"line":185},[119,1026,188],{"class":133},[119,1028,1029],{"class":121,"line":441},[119,1030,1032],{"emptyLinePlaceholder":1031},true,"\n",[119,1034,1035,1037,1039,1041,1043,1045,1047],{"class":121,"line":452},[119,1036,126],{"class":125},[119,1038,829],{"class":129},[119,1040,329],{"class":133},[119,1042,834],{"class":143},[119,1044,147],{"class":125},[119,1046,789],{"class":129},[119,1048,505],{"class":133},[119,1050,1051,1053],{"class":121,"line":458},[119,1052,845],{"class":125},[119,1054,848],{"class":133},[119,1056,1057,1059,1061],{"class":121,"line":464},[119,1058,853],{"class":125},[119,1060,856],{"class":585},[119,1062,859],{"class":133},[119,1064,1065,1067],{"class":121,"line":712},[119,1066,864],{"class":125},[119,1068,867],{"class":585},[119,1070,1071,1073,1075],{"class":121,"line":902},[119,1072,853],{"class":125},[119,1074,874],{"class":585},[119,1076,859],{"class":133},[119,1078,1079,1081],{"class":121,"line":908},[119,1080,864],{"class":125},[119,1082,883],{"class":585},[119,1084,1086,1088,1090],{"class":121,"line":1085},11,[119,1087,853],{"class":125},[119,1089,890],{"class":585},[119,1091,859],{"class":133},[119,1093,1095,1097],{"class":121,"line":1094},12,[119,1096,864],{"class":125},[119,1098,899],{"class":585},[119,1100,1102,1105],{"class":121,"line":1101},13,[119,1103,1104],{"class":125},"    default",[119,1106,859],{"class":133},[119,1108,1110,1112,1114],{"class":121,"line":1109},14,[119,1111,864],{"class":125},[119,1113,981],{"class":129},[119,1115,1116],{"class":133},"(status)\n",[119,1118,1120],{"class":121,"line":1119},15,[119,1121,905],{"class":133},[119,1123,1125],{"class":121,"line":1124},16,[119,1126,188],{"class":133},[11,1128,1129],{},"Now adding a new status produces a compiler error.",[11,1131,1132],{},"This is especially valuable in large codebases.",[11,1134,1135],{},"The type definition becomes the source of truth, and the compiler identifies all the places that need to change.",[92,1137,1139,1140,1143],{"id":1138},"_5-use-readonly-to-communicate-intent","5. Use ",[116,1141,1142],{},"readonly"," to Communicate Intent",[11,1145,1146],{},"Types aren’t only about what values are allowed.",[11,1148,1149],{},"They’re also about how those values are supposed to be used.",[11,1151,107],{},[109,1153,1155],{"className":111,"code":1154,"language":113,"meta":114,"style":114},"type User = {\n  readonly id: string\n  name: string\n}\n",[116,1156,1157,1167,1179,1188],{"__ignoreMap":114},[119,1158,1159,1161,1163,1165],{"class":121,"line":122},[119,1160,786],{"class":125},[119,1162,209],{"class":129},[119,1164,241],{"class":125},[119,1166,167],{"class":133},[119,1168,1169,1172,1175,1177],{"class":121,"line":170},[119,1170,1171],{"class":125},"  readonly",[119,1173,1174],{"class":143}," id",[119,1176,147],{"class":125},[119,1178,555],{"class":163},[119,1180,1181,1184,1186],{"class":121,"line":185},[119,1182,1183],{"class":143},"  name",[119,1185,147],{"class":125},[119,1187,555],{"class":163},[119,1189,1190],{"class":121,"line":441},[119,1191,188],{"class":133},[11,1193,1194],{},"Now:",[109,1196,1198],{"className":111,"code":1197,"language":113,"meta":114,"style":114},"user.id = '123'\n",[116,1199,1200],{"__ignoreMap":114},[119,1201,1202,1205,1207],{"class":121,"line":122},[119,1203,1204],{"class":133},"user.id ",[119,1206,215],{"class":125},[119,1208,1209],{"class":585}," '123'\n",[11,1211,1212],{},"is rejected.",[11,1214,1215],{},"You can also make collections readonly:",[109,1217,1219],{"className":111,"code":1218,"language":113,"meta":114,"style":114},"function processUsers(users: readonly User[]) {\n  \u002F\u002F ...\n}\n",[116,1220,1221,1243,1247],{"__ignoreMap":114},[119,1222,1223,1225,1228,1230,1233,1235,1238,1240],{"class":121,"line":122},[119,1224,126],{"class":125},[119,1226,1227],{"class":129}," processUsers",[119,1229,329],{"class":133},[119,1231,1232],{"class":143},"users",[119,1234,147],{"class":125},[119,1236,1237],{"class":125}," readonly",[119,1239,209],{"class":129},[119,1241,1242],{"class":133},"[]) {\n",[119,1244,1245],{"class":121,"line":170},[119,1246,461],{"class":251},[119,1248,1249],{"class":121,"line":185},[119,1250,188],{"class":133},[11,1252,1253],{},"Now the function can read the collection without implying that it owns or mutates it.",[11,1255,1256],{},"This is particularly useful for:",[49,1258,1259,1262,1265,1268,1271],{},[52,1260,1261],{},"configuration",[52,1263,1264],{},"shared data",[52,1266,1267],{},"constants",[52,1269,1270],{},"function parameters",[52,1272,1273],{},"immutable state",[11,1275,1276],{},"The benefit isn’t just preventing a mutation.",[11,1278,1279],{},"It’s communicating intent to every developer who reads the type.",[92,1281,1283,1284,1287],{"id":1282},"_6-dont-use-recordstring-unknown-as-a-replacement-for-real-types","6. Don’t Use ",[116,1285,1286],{},"Record\u003Cstring, unknown>"," as a Replacement for Real Types",[11,1289,1290],{},"You’ve probably seen code like:",[109,1292,1294],{"className":111,"code":1293,"language":113,"meta":114,"style":114},"function process(data: Record\u003Cstring, unknown>) {\n  \u002F\u002F ...\n}\n",[116,1295,1296,1323,1327],{"__ignoreMap":114},[119,1297,1298,1300,1303,1305,1308,1310,1312,1314,1316,1318,1320],{"class":121,"line":122},[119,1299,126],{"class":125},[119,1301,1302],{"class":129}," process",[119,1304,329],{"class":133},[119,1306,1307],{"class":143},"data",[119,1309,147],{"class":125},[119,1311,409],{"class":129},[119,1313,134],{"class":133},[119,1315,414],{"class":163},[119,1317,417],{"class":133},[119,1319,420],{"class":163},[119,1321,1322],{"class":133},">) {\n",[119,1324,1325],{"class":121,"line":170},[119,1326,461],{"class":251},[119,1328,1329],{"class":121,"line":185},[119,1330,188],{"class":133},[11,1332,1333],{},"Sometimes that’s exactly what you need.",[11,1335,1336],{},"If the function accepts arbitrary key-value data, great.",[11,1338,1339],{},"But if you actually know what the object represents, model it.",[11,1341,1342],{},"Instead of:",[109,1344,1345],{"className":111,"code":1293,"language":113,"meta":114,"style":114},[116,1346,1347,1371,1375],{"__ignoreMap":114},[119,1348,1349,1351,1353,1355,1357,1359,1361,1363,1365,1367,1369],{"class":121,"line":122},[119,1350,126],{"class":125},[119,1352,1302],{"class":129},[119,1354,329],{"class":133},[119,1356,1307],{"class":143},[119,1358,147],{"class":125},[119,1360,409],{"class":129},[119,1362,134],{"class":133},[119,1364,414],{"class":163},[119,1366,417],{"class":133},[119,1368,420],{"class":163},[119,1370,1322],{"class":133},[119,1372,1373],{"class":121,"line":170},[119,1374,461],{"class":251},[119,1376,1377],{"class":121,"line":185},[119,1378,188],{"class":133},[11,1380,1381],{},"use:",[109,1383,1385],{"className":111,"code":1384,"language":113,"meta":114,"style":114},"type User = {\n  id: string\n  name: string\n}\n\nfunction process(user: User) {\n  \u002F\u002F ...\n}\n",[116,1386,1387,1397,1406,1414,1418,1422,1438,1442],{"__ignoreMap":114},[119,1388,1389,1391,1393,1395],{"class":121,"line":122},[119,1390,786],{"class":125},[119,1392,209],{"class":129},[119,1394,241],{"class":125},[119,1396,167],{"class":133},[119,1398,1399,1402,1404],{"class":121,"line":170},[119,1400,1401],{"class":143},"  id",[119,1403,147],{"class":125},[119,1405,555],{"class":163},[119,1407,1408,1410,1412],{"class":121,"line":185},[119,1409,1183],{"class":143},[119,1411,147],{"class":125},[119,1413,555],{"class":163},[119,1415,1416],{"class":121,"line":441},[119,1417,188],{"class":133},[119,1419,1420],{"class":121,"line":452},[119,1421,1032],{"emptyLinePlaceholder":1031},[119,1423,1424,1426,1428,1430,1432,1434,1436],{"class":121,"line":458},[119,1425,126],{"class":125},[119,1427,1302],{"class":129},[119,1429,329],{"class":133},[119,1431,498],{"class":143},[119,1433,147],{"class":125},[119,1435,209],{"class":129},[119,1437,505],{"class":133},[119,1439,1440],{"class":121,"line":464},[119,1441,461],{"class":251},[119,1443,1444],{"class":121,"line":712},[119,1445,188],{"class":133},[11,1447,1448],{},"The difference might look small.",[11,1450,1451],{},"The impact isn’t.",[11,1453,1454],{},"The second version gives you:",[49,1456,1457,1460,1463,1466,1469],{},[52,1458,1459],{},"autocomplete",[52,1461,1462],{},"documentation",[52,1464,1465],{},"refactoring support",[52,1467,1468],{},"compile-time guarantees",[52,1470,1471],{},"clearer intent",[11,1473,1474],{},"Broad types are useful at genuinely dynamic boundaries.",[11,1476,1477],{},"They shouldn’t become the default representation for everything.",[92,1479,1481],{"id":1480},"_7-make-function-apis-self-documenting","7. Make Function APIs Self-Documenting",[11,1483,107],{},[109,1485,1487],{"className":111,"code":1486,"language":113,"meta":114,"style":114},"createUser(\n  'Akshat',\n  'akshat@example.com',\n  true,\n  false,\n)\n",[116,1488,1489,1497,1504,1511,1518,1525],{"__ignoreMap":114},[119,1490,1491,1494],{"class":121,"line":122},[119,1492,1493],{"class":129},"createUser",[119,1495,1496],{"class":133},"(\n",[119,1498,1499,1502],{"class":121,"line":170},[119,1500,1501],{"class":585},"  'Akshat'",[119,1503,438],{"class":133},[119,1505,1506,1509],{"class":121,"line":185},[119,1507,1508],{"class":585},"  'akshat@example.com'",[119,1510,438],{"class":133},[119,1512,1513,1516],{"class":121,"line":441},[119,1514,1515],{"class":163},"  true",[119,1517,438],{"class":133},[119,1519,1520,1523],{"class":121,"line":452},[119,1521,1522],{"class":163},"  false",[119,1524,438],{"class":133},[119,1526,1527],{"class":121,"line":458},[119,1528,1022],{"class":133},[11,1530,1531],{},"What does each boolean mean?",[11,1533,1534],{},"You have to remember the function signature.",[11,1536,1537],{},"Now compare:",[109,1539,1541],{"className":111,"code":1540,"language":113,"meta":114,"style":114},"createUser({\n  name: 'Akshat',\n  email: 'akshat@example.com',\n  sendWelcomeEmail: true,\n  isAdmin: false,\n})\n",[116,1542,1543,1550,1560,1570,1580,1590],{"__ignoreMap":114},[119,1544,1545,1547],{"class":121,"line":122},[119,1546,1493],{"class":129},[119,1548,1549],{"class":133},"({\n",[119,1551,1552,1555,1558],{"class":121,"line":170},[119,1553,1554],{"class":133},"  name: ",[119,1556,1557],{"class":585},"'Akshat'",[119,1559,438],{"class":133},[119,1561,1562,1565,1568],{"class":121,"line":185},[119,1563,1564],{"class":133},"  email: ",[119,1566,1567],{"class":585},"'akshat@example.com'",[119,1569,438],{"class":133},[119,1571,1572,1575,1578],{"class":121,"line":441},[119,1573,1574],{"class":133},"  sendWelcomeEmail: ",[119,1576,1577],{"class":163},"true",[119,1579,438],{"class":133},[119,1581,1582,1585,1588],{"class":121,"line":452},[119,1583,1584],{"class":133},"  isAdmin: ",[119,1586,1587],{"class":163},"false",[119,1589,438],{"class":133},[119,1591,1592],{"class":121,"line":458},[119,1593,1594],{"class":133},"})\n",[11,1596,1597],{},"The API explains itself.",[109,1599,1601],{"className":111,"code":1600,"language":113,"meta":114,"style":114},"type CreateUserOptions = {\n  name: string\n  email: string\n  sendWelcomeEmail: boolean\n  isAdmin: boolean\n}\n\nfunction createUser(options: CreateUserOptions) {\n  \u002F\u002F ...\n}\n",[116,1602,1603,1614,1622,1631,1641,1650,1654,1658,1676,1680],{"__ignoreMap":114},[119,1604,1605,1607,1610,1612],{"class":121,"line":122},[119,1606,786],{"class":125},[119,1608,1609],{"class":129}," CreateUserOptions",[119,1611,241],{"class":125},[119,1613,167],{"class":133},[119,1615,1616,1618,1620],{"class":121,"line":170},[119,1617,1183],{"class":143},[119,1619,147],{"class":125},[119,1621,555],{"class":163},[119,1623,1624,1627,1629],{"class":121,"line":185},[119,1625,1626],{"class":143},"  email",[119,1628,147],{"class":125},[119,1630,555],{"class":163},[119,1632,1633,1636,1638],{"class":121,"line":441},[119,1634,1635],{"class":143},"  sendWelcomeEmail",[119,1637,147],{"class":125},[119,1639,1640],{"class":163}," boolean\n",[119,1642,1643,1646,1648],{"class":121,"line":452},[119,1644,1645],{"class":143},"  isAdmin",[119,1647,147],{"class":125},[119,1649,1640],{"class":163},[119,1651,1652],{"class":121,"line":458},[119,1653,188],{"class":133},[119,1655,1656],{"class":121,"line":464},[119,1657,1032],{"emptyLinePlaceholder":1031},[119,1659,1660,1662,1665,1667,1670,1672,1674],{"class":121,"line":712},[119,1661,126],{"class":125},[119,1663,1664],{"class":129}," createUser",[119,1666,329],{"class":133},[119,1668,1669],{"class":143},"options",[119,1671,147],{"class":125},[119,1673,1609],{"class":129},[119,1675,505],{"class":133},[119,1677,1678],{"class":121,"line":902},[119,1679,461],{"class":251},[119,1681,1682],{"class":121,"line":908},[119,1683,188],{"class":133},[11,1685,1686],{},"This becomes increasingly valuable as functions grow.",[11,1688,1689],{},"A function with two arguments might be perfectly readable.",[11,1691,1692],{},"A function with seven arguments is usually asking for trouble.",[11,1694,1695],{},"TypeScript gives us a convenient way to make complex function APIs much more explicit.",[11,1697,1698],{},"Use it.",[92,1700,1702],{"id":1701},"_8-organize-types-around-the-domain","8. Organize Types Around the Domain",[11,1704,1705,1706,1709],{},"A common pattern in large applications is a global ",[116,1707,1708],{},"types.ts"," file.",[11,1711,1712],{},"It starts small.",[11,1714,1715],{},"Then another developer adds a type.",[11,1717,1718],{},"Then another.",[11,1720,1721],{},"A year later:",[11,1723,1724,1726],{},[116,1725,1708],{}," contains hundreds of unrelated types.",[11,1728,1729],{},"Finding the type you need becomes a project-wide search exercise.",[11,1731,1732],{},"Instead, keep types close to the domain they describe.",[11,1734,1735],{},"For example:",[109,1737,1742],{"className":1738,"code":1740,"language":1741,"meta":114},[1739],"language-text","users\u002F\n  user.types.ts\n  user.service.ts\n  user.repository.ts\n\npayments\u002F\n  payment.types.ts\n  payment.service.ts\n  payment.repository.ts\n\nfacilities\u002F\n  facility.types.ts\n  facility.service.ts\n  facility.repository.ts\n","text",[116,1743,1740],{"__ignoreMap":114},[11,1745,1746],{},"The exact architecture isn’t important.",[11,1748,1749],{},"The principle is.",[11,1751,1752],{},"Types belong to the domain they describe.",[11,1754,1755],{},"When you understand where the business logic lives, you should have a good idea where its types live too.",[92,1757,1759],{"id":1758},"_9-dont-let-the-type-system-become-more-complicated-than-the-business-logic","9. Don’t Let the Type System Become More Complicated Than the Business Logic",[11,1761,1762],{},"TypeScript can do some incredible things.",[11,1764,1765],{},"Mapped types.",[11,1767,1768],{},"Conditional types.",[11,1770,1771],{},"Template literal types.",[11,1773,1774],{},"Recursive types.",[11,1776,1777,35],{},[116,1778,1779],{},"infer",[11,1781,1782],{},"Distributive conditional types.",[11,1784,1785],{},"You can build almost anything.",[11,1787,1788],{},"That doesn’t mean you should.",[11,1790,1791],{},"Consider a type like:",[109,1793,1795],{"className":111,"code":1794,"language":113,"meta":114,"style":114},"type Magic\u003CT> =\n  T extends infer U\n    ? U extends Record\u003Cstring, unknown>\n      ? {\n          [K in keyof U as K extends `${string}Id`\n            ? K\n            : never]: U[K]\n        }\n      : never\n    : never\n",[116,1796,1797,1814,1826,1849,1856,1886,1894,1915,1920,1928],{"__ignoreMap":114},[119,1798,1799,1801,1804,1806,1808,1811],{"class":121,"line":122},[119,1800,786],{"class":125},[119,1802,1803],{"class":129}," Magic",[119,1805,134],{"class":133},[119,1807,137],{"class":129},[119,1809,1810],{"class":133},"> ",[119,1812,1813],{"class":125},"=\n",[119,1815,1816,1818,1820,1823],{"class":121,"line":170},[119,1817,403],{"class":129},[119,1819,406],{"class":125},[119,1821,1822],{"class":125}," infer",[119,1824,1825],{"class":129}," U\n",[119,1827,1828,1831,1834,1836,1838,1840,1842,1844,1846],{"class":121,"line":185},[119,1829,1830],{"class":125},"    ?",[119,1832,1833],{"class":129}," U",[119,1835,406],{"class":125},[119,1837,409],{"class":129},[119,1839,134],{"class":133},[119,1841,414],{"class":163},[119,1843,417],{"class":133},[119,1845,420],{"class":163},[119,1847,1848],{"class":133},">\n",[119,1850,1851,1854],{"class":121,"line":441},[119,1852,1853],{"class":125},"      ?",[119,1855,167],{"class":133},[119,1857,1858,1861,1864,1866,1868,1870,1873,1876,1878,1881,1883],{"class":121,"line":452},[119,1859,1860],{"class":133},"          [",[119,1862,1863],{"class":129},"K",[119,1865,690],{"class":125},[119,1867,433],{"class":125},[119,1869,1833],{"class":129},[119,1871,1872],{"class":125}," as",[119,1874,1875],{"class":129}," K",[119,1877,406],{"class":125},[119,1879,1880],{"class":585}," `${",[119,1882,414],{"class":163},[119,1884,1885],{"class":585},"}Id`\n",[119,1887,1888,1891],{"class":121,"line":458},[119,1889,1890],{"class":125},"            ?",[119,1892,1893],{"class":129}," K\n",[119,1895,1896,1899,1901,1904,1906,1908,1911,1913],{"class":121,"line":464},[119,1897,1898],{"class":125},"            :",[119,1900,990],{"class":163},[119,1902,1903],{"class":133},"]",[119,1905,147],{"class":125},[119,1907,1833],{"class":129},[119,1909,1910],{"class":133},"[",[119,1912,1863],{"class":129},[119,1914,182],{"class":133},[119,1916,1917],{"class":121,"line":712},[119,1918,1919],{"class":133},"        }\n",[119,1921,1922,1925],{"class":121,"line":902},[119,1923,1924],{"class":125},"      :",[119,1926,1927],{"class":163}," never\n",[119,1929,1930,1933],{"class":121,"line":908},[119,1931,1932],{"class":125},"    :",[119,1934,1927],{"class":163},[11,1936,1937],{},"There are legitimate use cases for sophisticated type-level programming.",[11,1939,1940],{},"But there is also a point where you’ve created more complexity than you’ve removed.",[11,1942,1943],{},"If the next developer needs to understand a complicated type before they can understand the business logic, stop and ask:",[11,1945,1946],{},"Could this be simpler?",[11,1948,1949],{},"Sometimes the answer is no.",[11,1951,1952],{},"Sometimes the complexity is justified.",[11,1954,1955],{},"But don’t confuse cleverness with quality.",[11,1957,1958],{},"The best TypeScript is often boring.",[11,1960,1961],{},"Readable types beat impressive types.",[92,1963,1965],{"id":1964},"_10-take-tsconfig-seriously","10. Take tsconfig Seriously",[11,1967,1968],{},"One of the easiest ways to undermine TypeScript is to configure it so that it doesn’t catch the problems you’re relying on it to catch.",[11,1970,1971],{},"At minimum, understand options such as:",[109,1973,1977],{"className":1974,"code":1975,"language":1976,"meta":114,"style":114},"language-json shiki shiki-themes github-light github-dark","{\n  \"compilerOptions\": {\n    \"strict\": true,\n    \"noUncheckedIndexedAccess\": true,\n    \"exactOptionalPropertyTypes\": true\n  }\n}\n","json",[116,1978,1979,1984,1992,2004,2015,2025,2029],{"__ignoreMap":114},[119,1980,1981],{"class":121,"line":122},[119,1982,1983],{"class":133},"{\n",[119,1985,1986,1989],{"class":121,"line":170},[119,1987,1988],{"class":163},"  \"compilerOptions\"",[119,1990,1991],{"class":133},": {\n",[119,1993,1994,1997,2000,2002],{"class":121,"line":185},[119,1995,1996],{"class":163},"    \"strict\"",[119,1998,1999],{"class":133},": ",[119,2001,1577],{"class":163},[119,2003,438],{"class":133},[119,2005,2006,2009,2011,2013],{"class":121,"line":441},[119,2007,2008],{"class":163},"    \"noUncheckedIndexedAccess\"",[119,2010,1999],{"class":133},[119,2012,1577],{"class":163},[119,2014,438],{"class":133},[119,2016,2017,2020,2022],{"class":121,"line":452},[119,2018,2019],{"class":163},"    \"exactOptionalPropertyTypes\"",[119,2021,1999],{"class":133},[119,2023,2024],{"class":163},"true\n",[119,2026,2027],{"class":121,"line":458},[119,2028,905],{"class":133},[119,2030,2031],{"class":121,"line":464},[119,2032,188],{"class":133},[11,2034,2035],{},"The exact configuration will depend on your project.",[11,2037,2038],{},"A legacy codebase may not be able to enable every strict option immediately.",[11,2040,913],{},[11,2042,2043],{},"What’s important is understanding what your compiler is checking.",[11,2045,2046],{},"Especially:",[109,2048,2050],{"className":1974,"code":2049,"language":1976,"meta":114,"style":114},"\"strict\": true\n",[116,2051,2052],{"__ignoreMap":114},[119,2053,2054,2057,2059],{"class":121,"line":122},[119,2055,2056],{"class":585},"\"strict\"",[119,2058,1999],{"class":133},[119,2060,2024],{"class":163},[11,2062,2063],{},"Strict mode isn’t about making TypeScript annoying.",[11,2065,2066],{},"It’s about asking the compiler to be more honest about uncertainty.",[11,2068,2069],{},"And the whole reason we use TypeScript is to catch problems before users do.",[92,2071,2073],{"id":2072},"the-bigger-picture","The Bigger Picture",[11,2075,2076],{},"None of these practices are particularly useful because they’re clever TypeScript tricks.",[11,2078,2079],{},"They’re useful because they make your codebase easier to reason about.",[11,2081,2082],{},"Consider what happens when a new developer joins your team.",[11,2084,2085],{},"They encounter:",[109,2087,2089],{"className":111,"code":2088,"language":113,"meta":114,"style":114},"type Payment =\n  | {\n      status: 'SUCCESS'\n      transactionId: string\n    }\n  | {\n      status: 'FAILED'\n      error: string\n    }\n",[116,2090,2091,2100,2106,2116,2125,2130,2136,2145,2154],{"__ignoreMap":114},[119,2092,2093,2095,2098],{"class":121,"line":122},[119,2094,786],{"class":125},[119,2096,2097],{"class":129}," Payment",[119,2099,792],{"class":125},[119,2101,2102,2104],{"class":121,"line":170},[119,2103,797],{"class":125},[119,2105,167],{"class":133},[119,2107,2108,2111,2113],{"class":121,"line":185},[119,2109,2110],{"class":143},"      status",[119,2112,147],{"class":125},[119,2114,2115],{"class":585}," 'SUCCESS'\n",[119,2117,2118,2121,2123],{"class":121,"line":441},[119,2119,2120],{"class":143},"      transactionId",[119,2122,147],{"class":125},[119,2124,555],{"class":163},[119,2126,2127],{"class":121,"line":452},[119,2128,2129],{"class":133},"    }\n",[119,2131,2132,2134],{"class":121,"line":458},[119,2133,797],{"class":125},[119,2135,167],{"class":133},[119,2137,2138,2140,2142],{"class":121,"line":464},[119,2139,2110],{"class":143},[119,2141,147],{"class":125},[119,2143,2144],{"class":585}," 'FAILED'\n",[119,2146,2147,2150,2152],{"class":121,"line":712},[119,2148,2149],{"class":143},"      error",[119,2151,147],{"class":125},[119,2153,555],{"class":163},[119,2155,2156],{"class":121,"line":902},[119,2157,2129],{"class":133},[11,2159,2160],{},"They immediately know something about the domain.",[11,2162,2163],{},"A successful payment has a transaction ID.",[11,2165,2166],{},"A failed payment has an error.",[11,2168,2169],{},"The type itself communicates the business rule.",[11,2171,2172],{},"That’s what good TypeScript should do.",[11,2174,2175],{},"It shouldn’t just tell you:",[11,2177,2178],{},"“This property is a string.”",[11,2180,2181],{},"It should tell you:",[11,2183,2184],{},"“This is how this part of the system is supposed to behave.”",[92,2186,2188],{"id":2187},"a-practical-typescript-checklist","A Practical TypeScript Checklist",[11,2190,2191],{},"Before committing a piece of TypeScript, I like to ask:",[49,2193,2194,2204,2207,2210,2213,2216,2222,2225,2228,2231,2237,2240],{},[52,2195,2196,2197,2200,2201,2203],{},"Is there an ",[116,2198,2199],{},"any"," here that could be ",[116,2202,420],{}," or a real type?",[52,2205,2206],{},"Am I writing a type annotation that TypeScript can already infer?",[52,2208,2209],{},"Are my types representing valid domain states?",[52,2211,2212],{},"Am I making something optional because it’s genuinely optional?",[52,2214,2215],{},"Could a union represent this state more accurately?",[52,2217,2218,2219,2221],{},"Am I using ",[116,2220,552],{}," because the value is actually safe, or because I want the error to disappear?",[52,2223,2224],{},"Does this generic express a meaningful relationship?",[52,2226,2227],{},"Is this abstraction easier to understand than the code it replaced?",[52,2229,2230],{},"Does the function API communicate what its arguments mean?",[52,2232,2233,2234,2236],{},"Would ",[116,2235,1142],{}," make the intended ownership or immutability clearer?",[52,2238,2239],{},"Will the compiler tell me when this domain changes?",[52,2241,2242],{},"Can another developer understand this type without having to decode it?",[11,2244,2245],{},"That last question is perhaps the most important.",[92,2247,2249],{"id":2248},"typescript-is-a-design-tool","TypeScript Is a Design Tool",[11,2251,2252],{},"The more TypeScript you write, the less interesting the syntax becomes.",[11,2254,2255],{},"The interesting part is what you choose to express.",[11,2257,2258],{},"You can use TypeScript to describe:",[11,2260,2261],{},"“This is an object with some strings.”",[11,2263,2264],{},"Or you can use it to describe:",[11,2266,2267],{},"“This operation can be in one of four states, and each state guarantees a different set of properties.”",[11,2269,2270],{},"The second is much more valuable.",[11,2272,2273],{},"That’s why good TypeScript isn’t measured by how many advanced features a developer knows.",[11,2275,2276],{},"It’s measured by how effectively the type system helps the team understand, change, and maintain the software.",[11,2278,2279],{},"Types should make the codebase easier to reason about—not harder.",[11,2281,2282],{},"And when the compiler can enforce the rules your application already cares about, you’ve moved beyond using TypeScript as a safety net.",[11,2284,2285],{},"You’re using it as part of the architecture.",[11,2287,2288],{},"Thanks for reading.",[11,2290,2291],{},"If you found this article useful, consider sharing it with other developers.",[11,2293,2294],{},"Happy coding!",[2296,2297,2298],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":114,"searchDepth":170,"depth":170,"links":2300},[2301,2302,2303,2304,2306,2308,2310,2311,2312,2313,2314,2315,2316],{"id":94,"depth":170,"text":95},{"id":373,"depth":170,"text":374},{"id":528,"depth":170,"text":529},{"id":768,"depth":170,"text":2305},"4. Use never to Catch Incomplete Logic",{"id":1138,"depth":170,"text":2307},"5. Use readonly to Communicate Intent",{"id":1282,"depth":170,"text":2309},"6. Don’t Use Record\u003Cstring, unknown> as a Replacement for Real Types",{"id":1480,"depth":170,"text":1481},{"id":1701,"depth":170,"text":1702},{"id":1758,"depth":170,"text":1759},{"id":1964,"depth":170,"text":1965},{"id":2072,"depth":170,"text":2073},{"id":2187,"depth":170,"text":2188},{"id":2248,"depth":170,"text":2249},"2026-08-22",false,"md",{"src":2321,"alt":2322},"\u002Fimages\u002Fblog\u002F10-typescript-practices-that-make-your-codebase-better-cover.jpg","Cover graphic for ten TypeScript practices that improve readability and maintainability in growing codebases",{},"\u002Fblog\u002F10-typescript-practices-that-make-your-codebase-better",{"title":6,"description":13},"blog\u002F10-typescript-practices-that-make-your-codebase-better",[2328,2329,2330,2331,2332],"Typescript","JavaScript","Front End Development","Software Development","Typescript Tips","2026-08-25","ZTI9UM8SpwRt7j5TCwKwlrGKPYhcF2tCwkdU2jDlzZc",{"id":2336,"title":2337,"body":2338,"date":4564,"description":4565,"draft":2318,"extension":2319,"featured":1031,"image":4566,"meta":4569,"navigation":1031,"path":4570,"seo":4571,"stem":4572,"tags":4573,"updatedAt":2333,"__hash__":4577},"blog\u002Fblog\u002Fbuilding-a-reusable-expand-collapse-transition-component-in-vue-3-with-smooth-height-animation.md","Building a Reusable Expand\u002FCollapse Transition Component in Vue 3 (with Smooth Height Animation)",{"type":8,"value":2339,"toc":4546},[2340,2351,2354,2360,2367,2374,2380,2383,2405,2408,2412,2419,2439,2442,2446,2449,2552,2555,2573,2586,2623,2626,2637,2646,2656,2955,2960,2977,2980,2984,3025,3035,3039,3107,3113,3117,3129,3132,3135,3139,3175,3178,3186,3220,3226,3234,3241,3372,3385,3389,3476,3479,3535,3538,3542,3607,3621,3627,3631,4397,4400,4489,4493,4496,4517,4521,4537,4540,4543],[11,2341,2342,2343,2346,2347,2350],{},"Animating height in the browser is one of those things that sounds simple but quickly turns messy. CSS doesn’t transition well between ",[116,2344,2345],{},"height: 0"," and ",[116,2348,2349],{},"height: auto",", which is exactly what you need for expand\u002Fcollapse UI patterns like accordions, dropdowns, or dynamic content blocks.",[11,2352,2353],{},"In this article, we’ll break down a reusable Vue 3 Transition Component that solves this problem cleanly and globally—so you can plug it in anywhere and get smooth expand\u002Fcollapse animations.",[11,2355,28,2356,35],{},[21,2357,34],{"href":2358,"rel":2359},"https:\u002F\u002Fakshattriv.medium.com\u002Fbuilding-a-reusable-expand-collapse-transition-component-in-vue-3-with-smooth-height-animation-d03d41149f51",[33],[92,2361,2363,2364,2366],{"id":2362},"the-problem-why-height-auto-wont-animate","The Problem: Why ",[116,2365,2349],{}," Won’t Animate",[11,2368,2369,2370,2373],{},"CSS transitions require explicit numeric values. But ",[116,2371,2372],{},"auto"," isn’t a number—it’s computed dynamically by the browser. So this won’t work:",[109,2375,2378],{"className":2376,"code":2377,"language":1741,"meta":114},[1739],"height: 0 → height: auto ❌\n",[116,2379,2377],{"__ignoreMap":114},[11,2381,2382],{},"To animate height properly, we need to:",[2384,2385,2386,2389,2399],"ol",{},[52,2387,2388],{},"Measure the element’s actual height",[52,2390,2391,2392,2395,2396],{},"Animate from ",[116,2393,2394],{},"0px"," → ",[116,2397,2398],{},"\u003Cmeasured height>",[52,2400,2401,2402,2404],{},"Reset back to ",[116,2403,2372],{}," after animation completes",[11,2406,2407],{},"That’s exactly what this component does.",[92,2409,2411],{"id":2410},"core-idea-of-the-component","Core Idea of the Component",[11,2413,2414,2415,2418],{},"We leverage Vue’s ",[116,2416,2417],{},"\u003Ctransition>"," hooks:",[49,2420,2421,2427,2433],{},[52,2422,2423,2426],{},[116,2424,2425],{},"enter"," → when element is inserted",[52,2428,2429,2432],{},[116,2430,2431],{},"afterEnter"," → after expand animation completes",[52,2434,2435,2438],{},[116,2436,2437],{},"leave"," → when element is removed",[11,2440,2441],{},"These hooks give us full control over DOM styles during animation.",[92,2443,2445],{"id":2444},"the-component-code-explained","The Component Code (Explained)",[11,2447,2448],{},"Here’s the template from our component:",[109,2450,2454],{"className":2451,"code":2452,"language":2453,"meta":114,"style":114},"language-vue shiki shiki-themes github-light github-dark","\u003Ctemplate>\n  \u003Ctransition\n    name=\"expand\"\n    @enter=\"enter($el)\"\n    @after-enter=\"afterEnter($el)\"\n    @leave=\"leave($el)\"\n  >\n    \u003Cslot \u002F>\n  \u003C\u002Ftransition>\n\u003C\u002Ftemplate>\n","vue",[116,2455,2456,2466,2474,2484,2494,2504,2514,2519,2533,2543],{"__ignoreMap":114},[119,2457,2458,2460,2464],{"class":121,"line":122},[119,2459,134],{"class":133},[119,2461,2463],{"class":2462},"s9eBZ","template",[119,2465,1848],{"class":133},[119,2467,2468,2471],{"class":121,"line":170},[119,2469,2470],{"class":133},"  \u003C",[119,2472,2473],{"class":2462},"transition\n",[119,2475,2476,2479,2481],{"class":121,"line":185},[119,2477,2478],{"class":129},"    name",[119,2480,215],{"class":133},[119,2482,2483],{"class":585},"\"expand\"\n",[119,2485,2486,2489,2491],{"class":121,"line":441},[119,2487,2488],{"class":129},"    @enter",[119,2490,215],{"class":133},[119,2492,2493],{"class":585},"\"enter($el)\"\n",[119,2495,2496,2499,2501],{"class":121,"line":452},[119,2497,2498],{"class":129},"    @after-enter",[119,2500,215],{"class":133},[119,2502,2503],{"class":585},"\"afterEnter($el)\"\n",[119,2505,2506,2509,2511],{"class":121,"line":458},[119,2507,2508],{"class":129},"    @leave",[119,2510,215],{"class":133},[119,2512,2513],{"class":585},"\"leave($el)\"\n",[119,2515,2516],{"class":121,"line":464},[119,2517,2518],{"class":133},"  >\n",[119,2520,2521,2524,2527,2531],{"class":121,"line":712},[119,2522,2523],{"class":133},"    \u003C",[119,2525,2526],{"class":2462},"slot",[119,2528,2530],{"class":2529},"s7hpK"," \u002F",[119,2532,1848],{"class":133},[119,2534,2535,2538,2541],{"class":121,"line":902},[119,2536,2537],{"class":133},"  \u003C\u002F",[119,2539,2540],{"class":2462},"transition",[119,2542,1848],{"class":133},[119,2544,2545,2548,2550],{"class":121,"line":908},[119,2546,2547],{"class":133},"\u003C\u002F",[119,2549,2463],{"class":2462},[119,2551,1848],{"class":133},[11,2553,2554],{},"Let’s break this down.",[11,2556,2557,2558,2564,2565,417,2567,417,2570,2572],{},"Vue provides a built-in ",[21,2559,2562],{"href":2560,"rel":2561},"https:\u002F\u002Fvuejs.org\u002Fguide\u002Fbuilt-ins\u002Ftransition",[33],[116,2563,2417],{}," component that allows you to animate elements when they enter the DOM and leave the DOM. Instead of manually adding\u002Fremoving classes, Vue gives us lifecycle hooks like ",[116,2566,2425],{},[116,2568,2569],{},"after-enter",[116,2571,2437],{},", etc. We are using these hooks to control the animation.",[11,2574,2575,2576,2581,2582,2585],{},"And we are using Vue ",[21,2577,2580],{"href":2578,"rel":2579},"https:\u002F\u002Fvuejs.org\u002Fguide\u002Fcomponents\u002Fslots",[33],"slots"," for making this fully reusable. For anyone who is not familiar with slots, ",[116,2583,2584],{},"\u003Cslot \u002F>"," is one of the most powerful concepts in Vue. It acts like a placeholder for whatever content you pass into this component. Example usage:",[109,2587,2589],{"className":2451,"code":2588,"language":2453,"meta":114,"style":114},"\u003CTransitionExpand>\n  \u003Cdiv v-if=\"isOpen\">\n    Hello, I will expand!\n  \u003C\u002Fdiv>\n\u003C\u002FTransitionExpand>\n",[116,2590,2591,2600,2605,2610,2615],{"__ignoreMap":114},[119,2592,2593,2595,2598],{"class":121,"line":122},[119,2594,134],{"class":133},[119,2596,2597],{"class":2462},"TransitionExpand",[119,2599,1848],{"class":133},[119,2601,2602],{"class":121,"line":170},[119,2603,2604],{"class":133},"  \u003Cdiv v-if=\"isOpen\">\n",[119,2606,2607],{"class":121,"line":185},[119,2608,2609],{"class":133},"    Hello, I will expand!\n",[119,2611,2612],{"class":121,"line":441},[119,2613,2614],{"class":133},"  \u003C\u002Fdiv>\n",[119,2616,2617,2619,2621],{"class":121,"line":452},[119,2618,2547],{"class":133},[119,2620,2597],{"class":2462},[119,2622,1848],{"class":133},[11,2624,2625],{},"Now writing the animation logic in script setup. I am using TypeScript, but if you are using JavaScript that’s totally fine—just ignore the types.",[11,2627,2628,2629,417,2631,2633,2634,2636],{},"We need to define three functions: ",[116,2630,2425],{},[116,2632,2431],{},", and ",[116,2635,2437],{},". As their names suggest, these functions define what to do when the element enters the DOM, what changes to perform after it enters, and finally the actions we need to perform once it leaves the DOM.",[2638,2639,2641,2642,2645],"h3",{"id":2640},"function-1-enter-when-element-appears","Function 1: ",[116,2643,2644],{},"enter()"," — When Element Appears",[11,2647,2648,2649,2652,2653,2655],{},"Like I said before, this function runs when the element is inserted into the DOM (i.e., when ",[116,2650,2651],{},"v-if"," becomes ",[116,2654,1577],{},").",[109,2657,2659],{"className":111,"code":2658,"language":113,"meta":114,"style":114},"function enter(element: HTMLElement) {\n  const width = getComputedStyle(element).width\n\n  element.style.width = width\n  element.style.position = 'absolute'\n  element.style.visibility = 'hidden'\n  element.style.height = 'auto'\n\n  const { height, padding } = getComputedStyle(element)\n\n  element.style.removeProperty('position')\n  element.style.removeProperty('visibility')\n  element.style.removeProperty('width')\n  element.style.height = '0'\n  element.style.margin = '0'\n  element.style.padding = '0'\n\n  \u002F\u002F Force repaint to make sure the\n  \u002F\u002F animation is triggered correctly.\n  \u002F\u002F oxlint-disable-next-line no-unused-expressions\n  getComputedStyle(element).height\n\n  \u002F\u002F Trigger the animation.\n  \u002F\u002F We use `requestAnimationFrame` because we need\n  \u002F\u002F to make sure the browser has finished\n  \u002F\u002F painting after setting the `height`\n  \u002F\u002F to `0` in the line above.\n  requestAnimationFrame(() => {\n    element.style.height = height\n    element.style.padding = padding\n  })\n}\n",[116,2660,2661,2680,2696,2700,2710,2720,2730,2740,2744,2769,2773,2788,2801,2814,2823,2832,2841,2846,2852,2858,2864,2873,2878,2884,2890,2896,2902,2908,2922,2933,2944,2950],{"__ignoreMap":114},[119,2662,2663,2665,2668,2670,2673,2675,2678],{"class":121,"line":122},[119,2664,126],{"class":125},[119,2666,2667],{"class":129}," enter",[119,2669,329],{"class":133},[119,2671,2672],{"class":143},"element",[119,2674,147],{"class":125},[119,2676,2677],{"class":129}," HTMLElement",[119,2679,505],{"class":133},[119,2681,2682,2685,2688,2690,2693],{"class":121,"line":170},[119,2683,2684],{"class":125},"  const",[119,2686,2687],{"class":163}," width",[119,2689,241],{"class":125},[119,2691,2692],{"class":129}," getComputedStyle",[119,2694,2695],{"class":133},"(element).width\n",[119,2697,2698],{"class":121,"line":185},[119,2699,1032],{"emptyLinePlaceholder":1031},[119,2701,2702,2705,2707],{"class":121,"line":441},[119,2703,2704],{"class":133},"  element.style.width ",[119,2706,215],{"class":125},[119,2708,2709],{"class":133}," width\n",[119,2711,2712,2715,2717],{"class":121,"line":452},[119,2713,2714],{"class":133},"  element.style.position ",[119,2716,215],{"class":125},[119,2718,2719],{"class":585}," 'absolute'\n",[119,2721,2722,2725,2727],{"class":121,"line":458},[119,2723,2724],{"class":133},"  element.style.visibility ",[119,2726,215],{"class":125},[119,2728,2729],{"class":585}," 'hidden'\n",[119,2731,2732,2735,2737],{"class":121,"line":464},[119,2733,2734],{"class":133},"  element.style.height ",[119,2736,215],{"class":125},[119,2738,2739],{"class":585}," 'auto'\n",[119,2741,2742],{"class":121,"line":712},[119,2743,1032],{"emptyLinePlaceholder":1031},[119,2745,2746,2748,2751,2754,2756,2759,2762,2764,2766],{"class":121,"line":902},[119,2747,2684],{"class":125},[119,2749,2750],{"class":133}," { ",[119,2752,2753],{"class":163},"height",[119,2755,417],{"class":133},[119,2757,2758],{"class":163},"padding",[119,2760,2761],{"class":133}," } ",[119,2763,215],{"class":125},[119,2765,2692],{"class":129},[119,2767,2768],{"class":133},"(element)\n",[119,2770,2771],{"class":121,"line":908},[119,2772,1032],{"emptyLinePlaceholder":1031},[119,2774,2775,2778,2781,2783,2786],{"class":121,"line":1085},[119,2776,2777],{"class":133},"  element.style.",[119,2779,2780],{"class":129},"removeProperty",[119,2782,329],{"class":133},[119,2784,2785],{"class":585},"'position'",[119,2787,1022],{"class":133},[119,2789,2790,2792,2794,2796,2799],{"class":121,"line":1094},[119,2791,2777],{"class":133},[119,2793,2780],{"class":129},[119,2795,329],{"class":133},[119,2797,2798],{"class":585},"'visibility'",[119,2800,1022],{"class":133},[119,2802,2803,2805,2807,2809,2812],{"class":121,"line":1101},[119,2804,2777],{"class":133},[119,2806,2780],{"class":129},[119,2808,329],{"class":133},[119,2810,2811],{"class":585},"'width'",[119,2813,1022],{"class":133},[119,2815,2816,2818,2820],{"class":121,"line":1109},[119,2817,2734],{"class":133},[119,2819,215],{"class":125},[119,2821,2822],{"class":585}," '0'\n",[119,2824,2825,2828,2830],{"class":121,"line":1119},[119,2826,2827],{"class":133},"  element.style.margin ",[119,2829,215],{"class":125},[119,2831,2822],{"class":585},[119,2833,2834,2837,2839],{"class":121,"line":1124},[119,2835,2836],{"class":133},"  element.style.padding ",[119,2838,215],{"class":125},[119,2840,2822],{"class":585},[119,2842,2844],{"class":121,"line":2843},17,[119,2845,1032],{"emptyLinePlaceholder":1031},[119,2847,2849],{"class":121,"line":2848},18,[119,2850,2851],{"class":251},"  \u002F\u002F Force repaint to make sure the\n",[119,2853,2855],{"class":121,"line":2854},19,[119,2856,2857],{"class":251},"  \u002F\u002F animation is triggered correctly.\n",[119,2859,2861],{"class":121,"line":2860},20,[119,2862,2863],{"class":251},"  \u002F\u002F oxlint-disable-next-line no-unused-expressions\n",[119,2865,2867,2870],{"class":121,"line":2866},21,[119,2868,2869],{"class":129},"  getComputedStyle",[119,2871,2872],{"class":133},"(element).height\n",[119,2874,2876],{"class":121,"line":2875},22,[119,2877,1032],{"emptyLinePlaceholder":1031},[119,2879,2881],{"class":121,"line":2880},23,[119,2882,2883],{"class":251},"  \u002F\u002F Trigger the animation.\n",[119,2885,2887],{"class":121,"line":2886},24,[119,2888,2889],{"class":251},"  \u002F\u002F We use `requestAnimationFrame` because we need\n",[119,2891,2893],{"class":121,"line":2892},25,[119,2894,2895],{"class":251},"  \u002F\u002F to make sure the browser has finished\n",[119,2897,2899],{"class":121,"line":2898},26,[119,2900,2901],{"class":251},"  \u002F\u002F painting after setting the `height`\n",[119,2903,2905],{"class":121,"line":2904},27,[119,2906,2907],{"class":251},"  \u002F\u002F to `0` in the line above.\n",[119,2909,2911,2914,2917,2920],{"class":121,"line":2910},28,[119,2912,2913],{"class":129},"  requestAnimationFrame",[119,2915,2916],{"class":133},"(() ",[119,2918,2919],{"class":125},"=>",[119,2921,167],{"class":133},[119,2923,2925,2928,2930],{"class":121,"line":2924},29,[119,2926,2927],{"class":133},"    element.style.height ",[119,2929,215],{"class":125},[119,2931,2932],{"class":133}," height\n",[119,2934,2936,2939,2941],{"class":121,"line":2935},30,[119,2937,2938],{"class":133},"    element.style.padding ",[119,2940,215],{"class":125},[119,2942,2943],{"class":133}," padding\n",[119,2945,2947],{"class":121,"line":2946},31,[119,2948,2949],{"class":133},"  })\n",[119,2951,2953],{"class":121,"line":2952},32,[119,2954,188],{"class":133},[2956,2957,2959],"h4",{"id":2958},"capture-the-width","Capture the width",[109,2961,2963],{"className":111,"code":2962,"language":113,"meta":114,"style":114},"const width = getComputedStyle(element).width\n",[116,2964,2965],{"__ignoreMap":114},[119,2966,2967,2969,2971,2973,2975],{"class":121,"line":122},[119,2968,201],{"class":125},[119,2970,2687],{"class":163},[119,2972,241],{"class":125},[119,2974,2692],{"class":129},[119,2976,2695],{"class":133},[11,2978,2979],{},"We store the width because when we temporarily change styles, layout might break—and fixing width ensures stable measurement.",[2956,2981,2983],{"id":2982},"prepare-for-measurement","Prepare for measurement",[109,2985,2987],{"className":111,"code":2986,"language":113,"meta":114,"style":114},"element.style.width = width\nelement.style.position = 'absolute'\nelement.style.visibility = 'hidden'\nelement.style.height = 'auto'\n",[116,2988,2989,2998,3007,3016],{"__ignoreMap":114},[119,2990,2991,2994,2996],{"class":121,"line":122},[119,2992,2993],{"class":133},"element.style.width ",[119,2995,215],{"class":125},[119,2997,2709],{"class":133},[119,2999,3000,3003,3005],{"class":121,"line":170},[119,3001,3002],{"class":133},"element.style.position ",[119,3004,215],{"class":125},[119,3006,2719],{"class":585},[119,3008,3009,3012,3014],{"class":121,"line":185},[119,3010,3011],{"class":133},"element.style.visibility ",[119,3013,215],{"class":125},[119,3015,2729],{"class":585},[119,3017,3018,3021,3023],{"class":121,"line":441},[119,3019,3020],{"class":133},"element.style.height ",[119,3022,215],{"class":125},[119,3024,2739],{"class":585},[11,3026,3027,3028,3030,3031,3034],{},"We make the element absolute so it gets removed from normal layout, set visibility to hidden so the user doesn’t see the element, and set height to ",[116,3029,2372],{}," so the browser calculates the height for us. In the next line, ",[116,3032,3033],{},"const { height, padding } = getComputedStyle(element)"," we capture the height.",[2956,3036,3038],{"id":3037},"reset-styles-to-start-animation","Reset styles to start animation",[109,3040,3042],{"className":111,"code":3041,"language":113,"meta":114,"style":114},"element.style.removeProperty('position')\nelement.style.removeProperty('visibility')\nelement.style.removeProperty('width')\nelement.style.height = '0'\nelement.style.margin = '0'\nelement.style.padding = '0'\n",[116,3043,3044,3057,3069,3081,3089,3098],{"__ignoreMap":114},[119,3045,3046,3049,3051,3053,3055],{"class":121,"line":122},[119,3047,3048],{"class":133},"element.style.",[119,3050,2780],{"class":129},[119,3052,329],{"class":133},[119,3054,2785],{"class":585},[119,3056,1022],{"class":133},[119,3058,3059,3061,3063,3065,3067],{"class":121,"line":170},[119,3060,3048],{"class":133},[119,3062,2780],{"class":129},[119,3064,329],{"class":133},[119,3066,2798],{"class":585},[119,3068,1022],{"class":133},[119,3070,3071,3073,3075,3077,3079],{"class":121,"line":185},[119,3072,3048],{"class":133},[119,3074,2780],{"class":129},[119,3076,329],{"class":133},[119,3078,2811],{"class":585},[119,3080,1022],{"class":133},[119,3082,3083,3085,3087],{"class":121,"line":441},[119,3084,3020],{"class":133},[119,3086,215],{"class":125},[119,3088,2822],{"class":585},[119,3090,3091,3094,3096],{"class":121,"line":452},[119,3092,3093],{"class":133},"element.style.margin ",[119,3095,215],{"class":125},[119,3097,2822],{"class":585},[119,3099,3100,3103,3105],{"class":121,"line":458},[119,3101,3102],{"class":133},"element.style.padding ",[119,3104,215],{"class":125},[119,3106,2822],{"class":585},[11,3108,3109,3110,3112],{},"This brings the element back to normal flow, collapses it to ",[116,3111,2345],{},", and removes the spacing. This becomes our starting point of the animation.",[2956,3114,3116],{"id":3115},"force-reflow","Force reflow",[109,3118,3120],{"className":111,"code":3119,"language":113,"meta":114,"style":114},"getComputedStyle(element).height\n",[116,3121,3122],{"__ignoreMap":114},[119,3123,3124,3127],{"class":121,"line":122},[119,3125,3126],{"class":129},"getComputedStyle",[119,3128,2872],{"class":133},[11,3130,3131],{},"This line looks useless—but it’s critical.",[11,3133,3134],{},"It forces the browser to apply all style changes immediately. Without this, the browser might skip the animation and everything could jump directly to the final state.",[2956,3136,3138],{"id":3137},"animate-to-full-height","Animate to full height",[109,3140,3142],{"className":111,"code":3141,"language":113,"meta":114,"style":114},"requestAnimationFrame(() => {\n  element.style.height = height\n  element.style.padding = padding\n})\n",[116,3143,3144,3155,3163,3171],{"__ignoreMap":114},[119,3145,3146,3149,3151,3153],{"class":121,"line":122},[119,3147,3148],{"class":129},"requestAnimationFrame",[119,3150,2916],{"class":133},[119,3152,2919],{"class":125},[119,3154,167],{"class":133},[119,3156,3157,3159,3161],{"class":121,"line":170},[119,3158,2734],{"class":133},[119,3160,215],{"class":125},[119,3162,2932],{"class":133},[119,3164,3165,3167,3169],{"class":121,"line":185},[119,3166,2836],{"class":133},[119,3168,215],{"class":125},[119,3170,2943],{"class":133},[119,3172,3173],{"class":121,"line":441},[119,3174,1594],{"class":133},[11,3176,3177],{},"We wait for the next frame, then set the height to the actual value and restore padding.",[2638,3179,3181,3182,3185],{"id":3180},"function-2-afterenter-cleanup-after-animation","Function 2: ",[116,3183,3184],{},"afterEnter()"," — Cleanup After Animation",[109,3187,3189],{"className":111,"code":3188,"language":113,"meta":114,"style":114},"function afterEnter(element: HTMLElement) {\n  element.style.height = 'auto'\n}\n",[116,3190,3191,3208,3216],{"__ignoreMap":114},[119,3192,3193,3195,3198,3200,3202,3204,3206],{"class":121,"line":122},[119,3194,126],{"class":125},[119,3196,3197],{"class":129}," afterEnter",[119,3199,329],{"class":133},[119,3201,2672],{"class":143},[119,3203,147],{"class":125},[119,3205,2677],{"class":129},[119,3207,505],{"class":133},[119,3209,3210,3212,3214],{"class":121,"line":170},[119,3211,2734],{"class":133},[119,3213,215],{"class":125},[119,3215,2739],{"class":585},[119,3217,3218],{"class":121,"line":185},[119,3219,188],{"class":133},[11,3221,3222,3223,3225],{},"Once animation finishes, we reset height to ",[116,3224,2372],{},". The reason we do this is that future content changes should adjust normally—a fixed height would break responsiveness.",[2638,3227,3229,3230,3233],{"id":3228},"function-3-leave-when-element-disappears","Function 3: ",[116,3231,3232],{},"leave()"," — When Element Disappears",[11,3235,3236,3237,2652,3239,35],{},"This runs when ",[116,3238,2651],{},[116,3240,1587],{},[109,3242,3244],{"className":111,"code":3243,"language":113,"meta":114,"style":114},"function leave(element: HTMLElement) {\n  const { height, padding } = getComputedStyle(element)\n\n  element.style.height = height\n  element.style.padding = padding\n\n  \u002F\u002F Force repaint to make sure the\n  \u002F\u002F animation is triggered correctly.\n  \u002F\u002F oxlint-disable-next-line no-unused-expressions\n  getComputedStyle(element).height\n\n  requestAnimationFrame(() => {\n    element.style.height = '0'\n    element.style.margin = '0'\n    element.style.padding = '0'\n  })\n}\n",[116,3245,3246,3263,3283,3287,3295,3303,3307,3311,3315,3319,3325,3329,3339,3347,3356,3364,3368],{"__ignoreMap":114},[119,3247,3248,3250,3253,3255,3257,3259,3261],{"class":121,"line":122},[119,3249,126],{"class":125},[119,3251,3252],{"class":129}," leave",[119,3254,329],{"class":133},[119,3256,2672],{"class":143},[119,3258,147],{"class":125},[119,3260,2677],{"class":129},[119,3262,505],{"class":133},[119,3264,3265,3267,3269,3271,3273,3275,3277,3279,3281],{"class":121,"line":170},[119,3266,2684],{"class":125},[119,3268,2750],{"class":133},[119,3270,2753],{"class":163},[119,3272,417],{"class":133},[119,3274,2758],{"class":163},[119,3276,2761],{"class":133},[119,3278,215],{"class":125},[119,3280,2692],{"class":129},[119,3282,2768],{"class":133},[119,3284,3285],{"class":121,"line":185},[119,3286,1032],{"emptyLinePlaceholder":1031},[119,3288,3289,3291,3293],{"class":121,"line":441},[119,3290,2734],{"class":133},[119,3292,215],{"class":125},[119,3294,2932],{"class":133},[119,3296,3297,3299,3301],{"class":121,"line":452},[119,3298,2836],{"class":133},[119,3300,215],{"class":125},[119,3302,2943],{"class":133},[119,3304,3305],{"class":121,"line":458},[119,3306,1032],{"emptyLinePlaceholder":1031},[119,3308,3309],{"class":121,"line":464},[119,3310,2851],{"class":251},[119,3312,3313],{"class":121,"line":712},[119,3314,2857],{"class":251},[119,3316,3317],{"class":121,"line":902},[119,3318,2863],{"class":251},[119,3320,3321,3323],{"class":121,"line":908},[119,3322,2869],{"class":129},[119,3324,2872],{"class":133},[119,3326,3327],{"class":121,"line":1085},[119,3328,1032],{"emptyLinePlaceholder":1031},[119,3330,3331,3333,3335,3337],{"class":121,"line":1094},[119,3332,2913],{"class":129},[119,3334,2916],{"class":133},[119,3336,2919],{"class":125},[119,3338,167],{"class":133},[119,3340,3341,3343,3345],{"class":121,"line":1101},[119,3342,2927],{"class":133},[119,3344,215],{"class":125},[119,3346,2822],{"class":585},[119,3348,3349,3352,3354],{"class":121,"line":1109},[119,3350,3351],{"class":133},"    element.style.margin ",[119,3353,215],{"class":125},[119,3355,2822],{"class":585},[119,3357,3358,3360,3362],{"class":121,"line":1119},[119,3359,2938],{"class":133},[119,3361,215],{"class":125},[119,3363,2822],{"class":585},[119,3365,3366],{"class":121,"line":1124},[119,3367,2949],{"class":133},[119,3369,3370],{"class":121,"line":2843},[119,3371,188],{"class":133},[11,3373,3374,3375,3377,3378,3381,3382,3384],{},"This is very similar to the ",[116,3376,2425],{}," function but just reversed: we capture the current state, explicitly set the height and padding so animation starts from the exact visible state, force a reflow again with ",[116,3379,3380],{},"getComputedStyle(element).height"," (same reason as before), and finally animate the collapse in the next frame by setting everything to ",[116,3383,179],{},". This creates the smooth collapse effect.",[92,3386,3388],{"id":3387},"css-that-makes-it-smooth","CSS That Makes It Smooth",[109,3390,3394],{"className":3391,"code":3392,"language":3393,"meta":114,"style":114},"language-scss shiki shiki-themes github-light github-dark",".expand-enter-active,\n.expand-leave-active {\n  transition:\n    height 0.3s ease-in-out,\n    opacity 0.3s ease-in-out,\n    margin 0.3s ease-in-out;\n  overflow: hidden;\n}\n","scss",[116,3395,3396,3403,3410,3417,3433,3446,3460,3472],{"__ignoreMap":114},[119,3397,3398,3401],{"class":121,"line":122},[119,3399,3400],{"class":129},".expand-enter-active",[119,3402,438],{"class":133},[119,3404,3405,3408],{"class":121,"line":170},[119,3406,3407],{"class":129},".expand-leave-active",[119,3409,167],{"class":133},[119,3411,3412,3415],{"class":121,"line":185},[119,3413,3414],{"class":163},"  transition",[119,3416,859],{"class":133},[119,3418,3419,3422,3425,3428,3431],{"class":121,"line":441},[119,3420,3421],{"class":163},"    height",[119,3423,3424],{"class":163}," 0.3",[119,3426,3427],{"class":125},"s",[119,3429,3430],{"class":163}," ease-in-out",[119,3432,438],{"class":133},[119,3434,3435,3438,3440,3442,3444],{"class":121,"line":452},[119,3436,3437],{"class":163},"    opacity",[119,3439,3424],{"class":163},[119,3441,3427],{"class":125},[119,3443,3430],{"class":163},[119,3445,438],{"class":133},[119,3447,3448,3451,3453,3455,3457],{"class":121,"line":458},[119,3449,3450],{"class":163},"    margin",[119,3452,3424],{"class":163},[119,3454,3427],{"class":125},[119,3456,3430],{"class":163},[119,3458,3459],{"class":133},";\n",[119,3461,3462,3465,3467,3470],{"class":121,"line":464},[119,3463,3464],{"class":163},"  overflow",[119,3466,1999],{"class":133},[119,3468,3469],{"class":163},"hidden",[119,3471,3459],{"class":133},[119,3473,3474],{"class":121,"line":712},[119,3475,188],{"class":133},[11,3477,3478],{},"This defines what properties to animate, the duration, and easing.",[109,3480,3482],{"className":3391,"code":3481,"language":3393,"meta":114,"style":114},".expand-enter,\n.expand-leave-to {\n  height: 0;\n  opacity: 0;\n  margin: 0;\n}\n",[116,3483,3484,3491,3498,3509,3520,3531],{"__ignoreMap":114},[119,3485,3486,3489],{"class":121,"line":122},[119,3487,3488],{"class":129},".expand-enter",[119,3490,438],{"class":133},[119,3492,3493,3496],{"class":121,"line":170},[119,3494,3495],{"class":129},".expand-leave-to",[119,3497,167],{"class":133},[119,3499,3500,3503,3505,3507],{"class":121,"line":185},[119,3501,3502],{"class":163},"  height",[119,3504,1999],{"class":133},[119,3506,179],{"class":163},[119,3508,3459],{"class":133},[119,3510,3511,3514,3516,3518],{"class":121,"line":441},[119,3512,3513],{"class":163},"  opacity",[119,3515,1999],{"class":133},[119,3517,179],{"class":163},[119,3519,3459],{"class":133},[119,3521,3522,3525,3527,3529],{"class":121,"line":452},[119,3523,3524],{"class":163},"  margin",[119,3526,1999],{"class":133},[119,3528,179],{"class":163},[119,3530,3459],{"class":133},[119,3532,3533],{"class":121,"line":458},[119,3534,188],{"class":133},[11,3536,3537],{},"This defines the initial and final collapse state.",[92,3539,3541],{"id":3540},"performance-optimisations","Performance Optimisations",[109,3543,3545],{"className":2451,"code":3544,"language":2453,"meta":114,"style":114},"\u003Cstyle lang=\"scss\" scoped>\n* {\n  will-change: height;\n  backface-visibility: hidden;\n}\n\u003C\u002Fstyle>\n",[116,3546,3547,3566,3573,3584,3595,3599],{"__ignoreMap":114},[119,3548,3549,3551,3553,3556,3558,3561,3564],{"class":121,"line":122},[119,3550,134],{"class":133},[119,3552,2296],{"class":2462},[119,3554,3555],{"class":129}," lang",[119,3557,215],{"class":133},[119,3559,3560],{"class":585},"\"scss\"",[119,3562,3563],{"class":129}," scoped",[119,3565,1848],{"class":133},[119,3567,3568,3571],{"class":121,"line":170},[119,3569,3570],{"class":2462},"*",[119,3572,167],{"class":133},[119,3574,3575,3578,3580,3582],{"class":121,"line":185},[119,3576,3577],{"class":163},"  will-change",[119,3579,1999],{"class":133},[119,3581,2753],{"class":163},[119,3583,3459],{"class":133},[119,3585,3586,3589,3591,3593],{"class":121,"line":441},[119,3587,3588],{"class":163},"  backface-visibility",[119,3590,1999],{"class":133},[119,3592,3469],{"class":163},[119,3594,3459],{"class":133},[119,3596,3597],{"class":121,"line":452},[119,3598,188],{"class":133},[119,3600,3601,3603,3605],{"class":121,"line":458},[119,3602,2547],{"class":133},[119,3604,2296],{"class":2462},[119,3606,1848],{"class":133},[49,3608,3609,3615],{},[52,3610,3611,3614],{},[116,3612,3613],{},"will-change"," → tells the browser to prepare for animation",[52,3616,3617,3620],{},[116,3618,3619],{},"backface-visibility"," → reduces rendering glitches",[11,3622,3623,3624,3626],{},"We have marked it scoped and used ",[116,3625,3570],{}," to apply this to everything in the component.",[92,3628,3630],{"id":3629},"final-code-usage-example","Final Code & Usage Example",[109,3632,3634],{"className":2451,"code":3633,"language":2453,"meta":114,"style":114},"\u003Cscript lang=\"ts\" setup>\nfunction enter(element: HTMLElement) {\n  const width = getComputedStyle(element).width\n\n  element.style.width = width\n  element.style.position = 'absolute'\n  element.style.visibility = 'hidden'\n  element.style.height = 'auto'\n\n  const { height, padding } = getComputedStyle(element)\n\n  element.style.removeProperty('position')\n  element.style.removeProperty('visibility')\n  element.style.removeProperty('width')\n  element.style.height = '0'\n  element.style.margin = '0'\n  element.style.padding = '0'\n\n  \u002F\u002F Force repaint to make sure the\n  \u002F\u002F animation is triggered correctly.\n  \u002F\u002F oxlint-disable-next-line no-unused-expressions\n  getComputedStyle(element).height\n\n  \u002F\u002F Trigger the animation.\n  \u002F\u002F We use `requestAnimationFrame` because we need\n  \u002F\u002F to make sure the browser has finished\n  \u002F\u002F painting after setting the `height`\n  \u002F\u002F to `0` in the line above.\n  requestAnimationFrame(() => {\n    element.style.height = height\n    element.style.padding = padding\n  })\n}\n\nfunction afterEnter(element: HTMLElement) {\n  element.style.height = 'auto'\n}\n\nfunction leave(element: HTMLElement) {\n  const { height, padding } = getComputedStyle(element)\n\n  element.style.height = height\n  element.style.padding = padding\n\n  \u002F\u002F Force repaint to make sure the\n  \u002F\u002F animation is triggered correctly.\n  \u002F\u002F oxlint-disable-next-line no-unused-expressions\n  getComputedStyle(element).height\n\n  requestAnimationFrame(() => {\n    element.style.height = '0'\n    element.style.margin = '0'\n    element.style.padding = '0'\n  })\n}\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Ctransition\n    name=\"expand\"\n    @enter=\"enter($el)\"\n    @after-enter=\"afterEnter($el)\"\n    @leave=\"leave($el)\"\n  >\n    \u003Cslot \u002F>\n  \u003C\u002Ftransition>\n\u003C\u002Ftemplate>\n\n\u003Cstyle lang=\"scss\">\n.expand-enter-active,\n.expand-leave-active {\n  transition:\n    height 0.3s ease-in-out,\n    opacity 0.3s ease-in-out,\n    margin 0.3s ease-in-out;\n  overflow: hidden;\n}\n\n.expand-enter,\n.expand-leave-to {\n  height: 0;\n  opacity: 0;\n  margin: 0;\n}\n\u003C\u002Fstyle>\n\n\u003Cstyle lang=\"scss\" scoped>\n* {\n  will-change: height;\n  backface-visibility: hidden;\n}\n\u003C\u002Fstyle>\n",[116,3635,3636,3655,3671,3683,3687,3695,3703,3711,3719,3723,3743,3747,3759,3771,3783,3791,3799,3807,3811,3815,3819,3823,3829,3833,3837,3841,3845,3849,3853,3863,3871,3879,3883,3888,3893,3910,3919,3924,3929,3946,3967,3972,3981,3990,3995,4000,4005,4010,4017,4022,4033,4042,4051,4060,4065,4070,4079,4084,4093,4100,4109,4118,4127,4136,4141,4152,4161,4170,4175,4190,4197,4204,4211,4224,4237,4250,4261,4266,4271,4278,4285,4296,4307,4318,4323,4332,4337,4354,4361,4372,4383,4388],{"__ignoreMap":114},[119,3637,3638,3640,3643,3645,3647,3650,3653],{"class":121,"line":122},[119,3639,134],{"class":133},[119,3641,3642],{"class":2462},"script",[119,3644,3555],{"class":129},[119,3646,215],{"class":133},[119,3648,3649],{"class":585},"\"ts\"",[119,3651,3652],{"class":129}," setup",[119,3654,1848],{"class":133},[119,3656,3657,3659,3661,3663,3665,3667,3669],{"class":121,"line":170},[119,3658,126],{"class":125},[119,3660,2667],{"class":129},[119,3662,329],{"class":133},[119,3664,2672],{"class":143},[119,3666,147],{"class":125},[119,3668,2677],{"class":129},[119,3670,505],{"class":133},[119,3672,3673,3675,3677,3679,3681],{"class":121,"line":185},[119,3674,2684],{"class":125},[119,3676,2687],{"class":163},[119,3678,241],{"class":125},[119,3680,2692],{"class":129},[119,3682,2695],{"class":133},[119,3684,3685],{"class":121,"line":441},[119,3686,1032],{"emptyLinePlaceholder":1031},[119,3688,3689,3691,3693],{"class":121,"line":452},[119,3690,2704],{"class":133},[119,3692,215],{"class":125},[119,3694,2709],{"class":133},[119,3696,3697,3699,3701],{"class":121,"line":458},[119,3698,2714],{"class":133},[119,3700,215],{"class":125},[119,3702,2719],{"class":585},[119,3704,3705,3707,3709],{"class":121,"line":464},[119,3706,2724],{"class":133},[119,3708,215],{"class":125},[119,3710,2729],{"class":585},[119,3712,3713,3715,3717],{"class":121,"line":712},[119,3714,2734],{"class":133},[119,3716,215],{"class":125},[119,3718,2739],{"class":585},[119,3720,3721],{"class":121,"line":902},[119,3722,1032],{"emptyLinePlaceholder":1031},[119,3724,3725,3727,3729,3731,3733,3735,3737,3739,3741],{"class":121,"line":908},[119,3726,2684],{"class":125},[119,3728,2750],{"class":133},[119,3730,2753],{"class":163},[119,3732,417],{"class":133},[119,3734,2758],{"class":163},[119,3736,2761],{"class":133},[119,3738,215],{"class":125},[119,3740,2692],{"class":129},[119,3742,2768],{"class":133},[119,3744,3745],{"class":121,"line":1085},[119,3746,1032],{"emptyLinePlaceholder":1031},[119,3748,3749,3751,3753,3755,3757],{"class":121,"line":1094},[119,3750,2777],{"class":133},[119,3752,2780],{"class":129},[119,3754,329],{"class":133},[119,3756,2785],{"class":585},[119,3758,1022],{"class":133},[119,3760,3761,3763,3765,3767,3769],{"class":121,"line":1101},[119,3762,2777],{"class":133},[119,3764,2780],{"class":129},[119,3766,329],{"class":133},[119,3768,2798],{"class":585},[119,3770,1022],{"class":133},[119,3772,3773,3775,3777,3779,3781],{"class":121,"line":1109},[119,3774,2777],{"class":133},[119,3776,2780],{"class":129},[119,3778,329],{"class":133},[119,3780,2811],{"class":585},[119,3782,1022],{"class":133},[119,3784,3785,3787,3789],{"class":121,"line":1119},[119,3786,2734],{"class":133},[119,3788,215],{"class":125},[119,3790,2822],{"class":585},[119,3792,3793,3795,3797],{"class":121,"line":1124},[119,3794,2827],{"class":133},[119,3796,215],{"class":125},[119,3798,2822],{"class":585},[119,3800,3801,3803,3805],{"class":121,"line":2843},[119,3802,2836],{"class":133},[119,3804,215],{"class":125},[119,3806,2822],{"class":585},[119,3808,3809],{"class":121,"line":2848},[119,3810,1032],{"emptyLinePlaceholder":1031},[119,3812,3813],{"class":121,"line":2854},[119,3814,2851],{"class":251},[119,3816,3817],{"class":121,"line":2860},[119,3818,2857],{"class":251},[119,3820,3821],{"class":121,"line":2866},[119,3822,2863],{"class":251},[119,3824,3825,3827],{"class":121,"line":2875},[119,3826,2869],{"class":129},[119,3828,2872],{"class":133},[119,3830,3831],{"class":121,"line":2880},[119,3832,1032],{"emptyLinePlaceholder":1031},[119,3834,3835],{"class":121,"line":2886},[119,3836,2883],{"class":251},[119,3838,3839],{"class":121,"line":2892},[119,3840,2889],{"class":251},[119,3842,3843],{"class":121,"line":2898},[119,3844,2895],{"class":251},[119,3846,3847],{"class":121,"line":2904},[119,3848,2901],{"class":251},[119,3850,3851],{"class":121,"line":2910},[119,3852,2907],{"class":251},[119,3854,3855,3857,3859,3861],{"class":121,"line":2924},[119,3856,2913],{"class":129},[119,3858,2916],{"class":133},[119,3860,2919],{"class":125},[119,3862,167],{"class":133},[119,3864,3865,3867,3869],{"class":121,"line":2935},[119,3866,2927],{"class":133},[119,3868,215],{"class":125},[119,3870,2932],{"class":133},[119,3872,3873,3875,3877],{"class":121,"line":2946},[119,3874,2938],{"class":133},[119,3876,215],{"class":125},[119,3878,2943],{"class":133},[119,3880,3881],{"class":121,"line":2952},[119,3882,2949],{"class":133},[119,3884,3886],{"class":121,"line":3885},33,[119,3887,188],{"class":133},[119,3889,3891],{"class":121,"line":3890},34,[119,3892,1032],{"emptyLinePlaceholder":1031},[119,3894,3896,3898,3900,3902,3904,3906,3908],{"class":121,"line":3895},35,[119,3897,126],{"class":125},[119,3899,3197],{"class":129},[119,3901,329],{"class":133},[119,3903,2672],{"class":143},[119,3905,147],{"class":125},[119,3907,2677],{"class":129},[119,3909,505],{"class":133},[119,3911,3913,3915,3917],{"class":121,"line":3912},36,[119,3914,2734],{"class":133},[119,3916,215],{"class":125},[119,3918,2739],{"class":585},[119,3920,3922],{"class":121,"line":3921},37,[119,3923,188],{"class":133},[119,3925,3927],{"class":121,"line":3926},38,[119,3928,1032],{"emptyLinePlaceholder":1031},[119,3930,3932,3934,3936,3938,3940,3942,3944],{"class":121,"line":3931},39,[119,3933,126],{"class":125},[119,3935,3252],{"class":129},[119,3937,329],{"class":133},[119,3939,2672],{"class":143},[119,3941,147],{"class":125},[119,3943,2677],{"class":129},[119,3945,505],{"class":133},[119,3947,3949,3951,3953,3955,3957,3959,3961,3963,3965],{"class":121,"line":3948},40,[119,3950,2684],{"class":125},[119,3952,2750],{"class":133},[119,3954,2753],{"class":163},[119,3956,417],{"class":133},[119,3958,2758],{"class":163},[119,3960,2761],{"class":133},[119,3962,215],{"class":125},[119,3964,2692],{"class":129},[119,3966,2768],{"class":133},[119,3968,3970],{"class":121,"line":3969},41,[119,3971,1032],{"emptyLinePlaceholder":1031},[119,3973,3975,3977,3979],{"class":121,"line":3974},42,[119,3976,2734],{"class":133},[119,3978,215],{"class":125},[119,3980,2932],{"class":133},[119,3982,3984,3986,3988],{"class":121,"line":3983},43,[119,3985,2836],{"class":133},[119,3987,215],{"class":125},[119,3989,2943],{"class":133},[119,3991,3993],{"class":121,"line":3992},44,[119,3994,1032],{"emptyLinePlaceholder":1031},[119,3996,3998],{"class":121,"line":3997},45,[119,3999,2851],{"class":251},[119,4001,4003],{"class":121,"line":4002},46,[119,4004,2857],{"class":251},[119,4006,4008],{"class":121,"line":4007},47,[119,4009,2863],{"class":251},[119,4011,4013,4015],{"class":121,"line":4012},48,[119,4014,2869],{"class":129},[119,4016,2872],{"class":133},[119,4018,4020],{"class":121,"line":4019},49,[119,4021,1032],{"emptyLinePlaceholder":1031},[119,4023,4025,4027,4029,4031],{"class":121,"line":4024},50,[119,4026,2913],{"class":129},[119,4028,2916],{"class":133},[119,4030,2919],{"class":125},[119,4032,167],{"class":133},[119,4034,4036,4038,4040],{"class":121,"line":4035},51,[119,4037,2927],{"class":133},[119,4039,215],{"class":125},[119,4041,2822],{"class":585},[119,4043,4045,4047,4049],{"class":121,"line":4044},52,[119,4046,3351],{"class":133},[119,4048,215],{"class":125},[119,4050,2822],{"class":585},[119,4052,4054,4056,4058],{"class":121,"line":4053},53,[119,4055,2938],{"class":133},[119,4057,215],{"class":125},[119,4059,2822],{"class":585},[119,4061,4063],{"class":121,"line":4062},54,[119,4064,2949],{"class":133},[119,4066,4068],{"class":121,"line":4067},55,[119,4069,188],{"class":133},[119,4071,4073,4075,4077],{"class":121,"line":4072},56,[119,4074,2547],{"class":133},[119,4076,3642],{"class":2462},[119,4078,1848],{"class":133},[119,4080,4082],{"class":121,"line":4081},57,[119,4083,1032],{"emptyLinePlaceholder":1031},[119,4085,4087,4089,4091],{"class":121,"line":4086},58,[119,4088,134],{"class":133},[119,4090,2463],{"class":2462},[119,4092,1848],{"class":133},[119,4094,4096,4098],{"class":121,"line":4095},59,[119,4097,2470],{"class":133},[119,4099,2473],{"class":2462},[119,4101,4103,4105,4107],{"class":121,"line":4102},60,[119,4104,2478],{"class":129},[119,4106,215],{"class":133},[119,4108,2483],{"class":585},[119,4110,4112,4114,4116],{"class":121,"line":4111},61,[119,4113,2488],{"class":129},[119,4115,215],{"class":133},[119,4117,2493],{"class":585},[119,4119,4121,4123,4125],{"class":121,"line":4120},62,[119,4122,2498],{"class":129},[119,4124,215],{"class":133},[119,4126,2503],{"class":585},[119,4128,4130,4132,4134],{"class":121,"line":4129},63,[119,4131,2508],{"class":129},[119,4133,215],{"class":133},[119,4135,2513],{"class":585},[119,4137,4139],{"class":121,"line":4138},64,[119,4140,2518],{"class":133},[119,4142,4144,4146,4148,4150],{"class":121,"line":4143},65,[119,4145,2523],{"class":133},[119,4147,2526],{"class":2462},[119,4149,2530],{"class":2529},[119,4151,1848],{"class":133},[119,4153,4155,4157,4159],{"class":121,"line":4154},66,[119,4156,2537],{"class":133},[119,4158,2540],{"class":2462},[119,4160,1848],{"class":133},[119,4162,4164,4166,4168],{"class":121,"line":4163},67,[119,4165,2547],{"class":133},[119,4167,2463],{"class":2462},[119,4169,1848],{"class":133},[119,4171,4173],{"class":121,"line":4172},68,[119,4174,1032],{"emptyLinePlaceholder":1031},[119,4176,4178,4180,4182,4184,4186,4188],{"class":121,"line":4177},69,[119,4179,134],{"class":133},[119,4181,2296],{"class":2462},[119,4183,3555],{"class":129},[119,4185,215],{"class":133},[119,4187,3560],{"class":585},[119,4189,1848],{"class":133},[119,4191,4193,4195],{"class":121,"line":4192},70,[119,4194,3400],{"class":129},[119,4196,438],{"class":133},[119,4198,4200,4202],{"class":121,"line":4199},71,[119,4201,3407],{"class":129},[119,4203,167],{"class":133},[119,4205,4207,4209],{"class":121,"line":4206},72,[119,4208,3414],{"class":163},[119,4210,859],{"class":133},[119,4212,4214,4216,4218,4220,4222],{"class":121,"line":4213},73,[119,4215,3421],{"class":163},[119,4217,3424],{"class":163},[119,4219,3427],{"class":125},[119,4221,3430],{"class":163},[119,4223,438],{"class":133},[119,4225,4227,4229,4231,4233,4235],{"class":121,"line":4226},74,[119,4228,3437],{"class":163},[119,4230,3424],{"class":163},[119,4232,3427],{"class":125},[119,4234,3430],{"class":163},[119,4236,438],{"class":133},[119,4238,4240,4242,4244,4246,4248],{"class":121,"line":4239},75,[119,4241,3450],{"class":163},[119,4243,3424],{"class":163},[119,4245,3427],{"class":125},[119,4247,3430],{"class":163},[119,4249,3459],{"class":133},[119,4251,4253,4255,4257,4259],{"class":121,"line":4252},76,[119,4254,3464],{"class":163},[119,4256,1999],{"class":133},[119,4258,3469],{"class":163},[119,4260,3459],{"class":133},[119,4262,4264],{"class":121,"line":4263},77,[119,4265,188],{"class":133},[119,4267,4269],{"class":121,"line":4268},78,[119,4270,1032],{"emptyLinePlaceholder":1031},[119,4272,4274,4276],{"class":121,"line":4273},79,[119,4275,3488],{"class":129},[119,4277,438],{"class":133},[119,4279,4281,4283],{"class":121,"line":4280},80,[119,4282,3495],{"class":129},[119,4284,167],{"class":133},[119,4286,4288,4290,4292,4294],{"class":121,"line":4287},81,[119,4289,3502],{"class":163},[119,4291,1999],{"class":133},[119,4293,179],{"class":163},[119,4295,3459],{"class":133},[119,4297,4299,4301,4303,4305],{"class":121,"line":4298},82,[119,4300,3513],{"class":163},[119,4302,1999],{"class":133},[119,4304,179],{"class":163},[119,4306,3459],{"class":133},[119,4308,4310,4312,4314,4316],{"class":121,"line":4309},83,[119,4311,3524],{"class":163},[119,4313,1999],{"class":133},[119,4315,179],{"class":163},[119,4317,3459],{"class":133},[119,4319,4321],{"class":121,"line":4320},84,[119,4322,188],{"class":133},[119,4324,4326,4328,4330],{"class":121,"line":4325},85,[119,4327,2547],{"class":133},[119,4329,2296],{"class":2462},[119,4331,1848],{"class":133},[119,4333,4335],{"class":121,"line":4334},86,[119,4336,1032],{"emptyLinePlaceholder":1031},[119,4338,4340,4342,4344,4346,4348,4350,4352],{"class":121,"line":4339},87,[119,4341,134],{"class":133},[119,4343,2296],{"class":2462},[119,4345,3555],{"class":129},[119,4347,215],{"class":133},[119,4349,3560],{"class":585},[119,4351,3563],{"class":129},[119,4353,1848],{"class":133},[119,4355,4357,4359],{"class":121,"line":4356},88,[119,4358,3570],{"class":2462},[119,4360,167],{"class":133},[119,4362,4364,4366,4368,4370],{"class":121,"line":4363},89,[119,4365,3577],{"class":163},[119,4367,1999],{"class":133},[119,4369,2753],{"class":163},[119,4371,3459],{"class":133},[119,4373,4375,4377,4379,4381],{"class":121,"line":4374},90,[119,4376,3588],{"class":163},[119,4378,1999],{"class":133},[119,4380,3469],{"class":163},[119,4382,3459],{"class":133},[119,4384,4386],{"class":121,"line":4385},91,[119,4387,188],{"class":133},[119,4389,4391,4393,4395],{"class":121,"line":4390},92,[119,4392,2547],{"class":133},[119,4394,2296],{"class":2462},[119,4396,1848],{"class":133},[11,4398,4399],{},"Usage:",[109,4401,4403],{"className":2451,"code":4402,"language":2453,"meta":114,"style":114},"\u003Ctemplate>\n  \u003Cbutton @click=\"isOpen = !isOpen\">\n    Toggle\n  \u003C\u002Fbutton>\n  \u003CTransitionExpand>\n    \u003Cdiv v-if=\"isOpen\">This content expands smoothly\u003C\u002Fdiv>\n  \u003C\u002FTransitionExpand>\n\u003C\u002Ftemplate>\n",[116,4404,4405,4413,4430,4435,4443,4451,4473,4481],{"__ignoreMap":114},[119,4406,4407,4409,4411],{"class":121,"line":122},[119,4408,134],{"class":133},[119,4410,2463],{"class":2462},[119,4412,1848],{"class":133},[119,4414,4415,4417,4420,4423,4425,4428],{"class":121,"line":170},[119,4416,2470],{"class":133},[119,4418,4419],{"class":2462},"button",[119,4421,4422],{"class":129}," @click",[119,4424,215],{"class":133},[119,4426,4427],{"class":585},"\"isOpen = !isOpen\"",[119,4429,1848],{"class":133},[119,4431,4432],{"class":121,"line":185},[119,4433,4434],{"class":133},"    Toggle\n",[119,4436,4437,4439,4441],{"class":121,"line":441},[119,4438,2537],{"class":133},[119,4440,4419],{"class":2462},[119,4442,1848],{"class":133},[119,4444,4445,4447,4449],{"class":121,"line":452},[119,4446,2470],{"class":133},[119,4448,2597],{"class":2462},[119,4450,1848],{"class":133},[119,4452,4453,4455,4458,4461,4463,4466,4469,4471],{"class":121,"line":458},[119,4454,2523],{"class":133},[119,4456,4457],{"class":2462},"div",[119,4459,4460],{"class":129}," v-if",[119,4462,215],{"class":133},[119,4464,4465],{"class":585},"\"isOpen\"",[119,4467,4468],{"class":133},">This content expands smoothly\u003C\u002F",[119,4470,4457],{"class":2462},[119,4472,1848],{"class":133},[119,4474,4475,4477,4479],{"class":121,"line":464},[119,4476,2537],{"class":133},[119,4478,2597],{"class":2462},[119,4480,1848],{"class":133},[119,4482,4483,4485,4487],{"class":121,"line":712},[119,4484,2547],{"class":133},[119,4486,2463],{"class":2462},[119,4488,1848],{"class":133},[92,4490,4492],{"id":4491},"final-understanding","Final Understanding",[11,4494,4495],{},"Here’s the full mental model:",[2384,4497,4498,4501,4506,4509,4511],{},[52,4499,4500],{},"Measure actual height (hidden)",[52,4502,4503,4504],{},"Collapse element to ",[116,4505,179],{},[52,4507,4508],{},"Force browser to apply styles",[52,4510,3138],{},[52,4512,4513,4514,4516],{},"Reset to ",[116,4515,2372],{}," after animation",[92,4518,4520],{"id":4519},"why-this-pattern-is-powerful","Why This Pattern is Powerful",[49,4522,4523,4526,4531,4534],{},[52,4524,4525],{},"Works with any dynamic content",[52,4527,4528,4529],{},"Fully reusable via ",[116,4530,2584],{},[52,4532,4533],{},"Gives smooth, professional UI",[52,4535,4536],{},"No external libraries needed",[11,4538,4539],{},"Once you understand this, you’ve basically unlocked a core frontend animation technique used in real-world production apps.",[11,4541,4542],{},"Thanks for reading—hope you learned something new. If you liked this article, please consider following me; I’ll be writing more such articles on Vue, front-end, and back-end. If you have any thoughts, share them in the comments, and see you next time.",[2296,4544,4545],{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .s7hpK, html code.shiki .s7hpK{--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}",{"title":114,"searchDepth":170,"depth":170,"links":4547},[4548,4550,4551,4559,4560,4561,4562,4563],{"id":2362,"depth":170,"text":4549},"The Problem: Why height: auto Won’t Animate",{"id":2410,"depth":170,"text":2411},{"id":2444,"depth":170,"text":2445,"children":4552},[4553,4555,4557],{"id":2640,"depth":185,"text":4554},"Function 1: enter() — When Element Appears",{"id":3180,"depth":185,"text":4556},"Function 2: afterEnter() — Cleanup After Animation",{"id":3228,"depth":185,"text":4558},"Function 3: leave() — When Element Disappears",{"id":3387,"depth":170,"text":3388},{"id":3540,"depth":170,"text":3541},{"id":3629,"depth":170,"text":3630},{"id":4491,"depth":170,"text":4492},{"id":4519,"depth":170,"text":4520},"2026-04-25","Build a reusable Vue 3 TransitionExpand component that animates height from 0 to auto using transition hooks, measured heights, and requestAnimationFrame.",{"src":4567,"alt":4568},"\u002Fimages\u002Fblog\u002Fbuilding-a-reusable-expand-collapse-transition-component-in-vue-3-with-smooth-height-animation-cover.jpg","Cover graphic for a reusable Vue 3 expand and collapse transition with smooth height animation",{},"\u002Fblog\u002Fbuilding-a-reusable-expand-collapse-transition-component-in-vue-3-with-smooth-height-animation",{"title":2337,"description":4565},"blog\u002Fbuilding-a-reusable-expand-collapse-transition-component-in-vue-3-with-smooth-height-animation",[4574,4575,2329,2330,4576],"Vuejs","Vue 3","CSS","eTh53rXaT-rb5TVkp_rF8uIL-DKpRw5IUNsggbhzLoA",{"id":4579,"title":4580,"body":4581,"date":6156,"description":6157,"draft":2318,"extension":2319,"featured":1031,"image":6158,"meta":6161,"navigation":1031,"path":6162,"seo":6163,"stem":6164,"tags":6165,"updatedAt":6169,"__hash__":6170},"blog\u002Fblog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3.md","Creating a customized alert and confirm function modal component which can stop function execution until the user responds in Vue 3",{"type":8,"value":4582,"toc":6147},[4583,4586,4604,4613,4619,4625,4631,4635,4649,4657,4660,4664,4678,4682,4776,4787,5503,5517,5523,5546,5574,5580,5602,5623,5627,5630,5643,5697,5704,6130,6135,6141,6144],[11,4584,4585],{},"Hi, that was probably the longest title I’ve ever written before. But it was necessary—there’s no clean way of summarizing the task.",[11,4587,4588,4589,2346,4592,4595,4596,4599,4600,4603],{},"In modern web development we make a lot of use of modals for alerting users and confirming actions. And of course, no one likes using the ",[116,4590,4591],{},"alert",[116,4593,4594],{},"confirm"," functions the browser APIs give us in JavaScript—browser default modals look horrible. But there’s one thing about those functions that intrigued me: they can stop script execution until they receive a user response. I wanted something similar—a way to ",[116,4597,4598],{},"await"," the user response from my own ",[116,4601,4602],{},"alertConfirm"," modal.",[11,4605,4606,4607,4610,4611,4603],{},"The reason for doing this could be that you don’t want to leave your current function, and you wish to perform certain actions based on the user response inside that function. The best use case I encountered was inside a ",[116,4608,4609],{},"beforeLeave"," route guard: I didn’t want to leave the route if the user clicked “No” in my ",[116,4612,4602],{},[11,4614,28,4615,35],{},[21,4616,34],{"href":4617,"rel":4618},"https:\u002F\u002Fmedium.com\u002Fcodetodeploy\u002Fcreating-a-customized-alert-and-confirm-function-modal-component-which-can-stop-function-execution-bb26914da78a",[33],[4620,4621],"article-figure",{"alt":4622,"caption":4623,"src":4624},"TypeScript openAlertConfirm function that awaits alertConfirm.value.openModal with an alert or confirm message","Calling openModal from a parent component and awaiting the boolean result.","\u002Fimages\u002Fblog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3\u002Fopen-modal-usage.png",[11,4626,4627,4628,4630],{},"The above image is an example of how this modal component will be used inside a view or any other component. The first parameter the function takes is the message you wish to display inside the modal. The second parameter is a Boolean—if ",[116,4629,1577],{},", the modal will be an alert and will have only one button.",[92,4632,4634],{"id":4633},"ui-screenshots-from-the-project","UI Screenshots from the project",[4636,4637,4639,4644],"article-gallery",{"label":4638},"Alert and confirm modal screenshots",[4620,4640],{"alt":4641,"caption":4642,"src":4643},"Dark-themed alert modal with a single Okay button and a checkmark icon","Alert mode: one Okay button.","\u002Fimages\u002Fblog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3\u002Falert-modal.png",[4620,4645],{"alt":4646,"caption":4647,"src":4648},"Dark-themed confirm modal with Yes and No buttons","Confirm mode: Yes and No buttons.","\u002Fimages\u002Fblog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3\u002Fconfirm-modal.png",[11,4650,4651,4652,35],{},"Project link: ",[21,4653,4656],{"href":4654,"rel":4655},"https:\u002F\u002Fgithub.com\u002Fakshat-triv\u002FCustom-Vue-Alert-Confirm-Modal",[33],"akshat-triv\u002FCustom-Vue-Alert-Confirm-Modal",[11,4658,4659],{},"I’m using Vite and TypeScript in my project, but that shouldn’t affect you even if you don’t know TypeScript—you can ignore the types.",[92,4661,4663],{"id":4662},"creating-the-alertconfirm-modal-component","Creating the AlertConfirm modal component",[11,4665,4666,4667,4670,4671,2346,4674,4677],{},"I’m using the Composition API and ",[116,4668,4669],{},"\u003Cscript setup>"," way of writing Vue SFCs. In the setup I’ve imported my button component, along with the icon components I want inside my buttons. I’ve also imported ",[116,4672,4673],{},"ref",[116,4675,4676],{},"computed"," from Vue.",[2638,4679,4681],{"id":4680},"refs-variables-and-computed-properties","Refs, variables, and computed properties",[2384,4683,4684,4695,4717,4725,4738,4749],{},[52,4685,4686,4692,4693,35],{},[4687,4688,4689],"strong",{},[116,4690,4691],{},"showConfirm"," — makes the modal visible when the value is ",[116,4694,1577],{},[52,4696,4697,4702,4703,4706,4707,4710,4711,4713,4714,4716],{},[4687,4698,4699],{},[116,4700,4701],{},"modalType"," — can only be ",[116,4704,4705],{},"\"confirm\""," or ",[116,4708,4709],{},"\"alert\"",". If the value is ",[116,4712,4705],{},", the modal has two buttons with the text “Yes” and “No”. If the value is ",[116,4715,4709],{},", the modal has only one button with the text “Okay”.",[52,4718,4719,4724],{},[4687,4720,4721],{},[116,4722,4723],{},"alertConfirmMessage"," — stores and displays the message text inside the modal.",[52,4726,4727,4732,4733,4735,4736,35],{},[4687,4728,4729],{},[116,4730,4731],{},"trueBtnText"," — a computed property for the button that returns ",[116,4734,1577],{},"; the label changes based on ",[116,4737,4701],{},[52,4739,4740,4745,4746,4748],{},[4687,4741,4742],{},[116,4743,4744],{},"falseBtnText"," — a ref for the text on the button that returns ",[116,4747,1587],{}," when clicked.",[52,4750,4751,4756,4757,4760,4761,4764,4765,4768,4769,4772,4773,35],{},[4687,4752,4753],{},[116,4754,4755],{},"resolvePromise"," — a ",[116,4758,4759],{},"let"," variable that later stores the ",[116,4762,4763],{},"resolve"," function’s reference. Don’t worry too much about this now—you’ll see why it matters. Its type is a function that takes a ",[116,4766,4767],{},"boolean"," (or ",[116,4770,4771],{},"PromiseLike\u003Cboolean>",") and returns ",[116,4774,4775],{},"void",[11,4777,4778,4779,4782,4783,4786],{},"Here’s the component (",[116,4780,4781],{},"AlertConfirm.vue"," in the article; the companion repo names the file ",[116,4784,4785],{},"AlertConfirmModal.vue","):",[109,4788,4790],{"className":2451,"code":4789,"language":2453,"meta":114,"style":114},"\u003Cscript lang=\"ts\" setup>\nimport { ref, computed } from 'vue'\n\nimport CommonButton from '@\u002Fcomponents\u002FCommonButton.vue'\nimport CheckIcon from '@\u002Fcomponents\u002Ficons\u002FIconCheck.vue'\nimport CrossIcon from '@\u002Fcomponents\u002Ficons\u002FIconCancel.vue'\n\nconst showConfirm = ref(false)\nlet resolvePromise: (value: PromiseLike\u003Cboolean> | boolean) => void\n\nconst modalType = ref\u003C'confirm' | 'alert'>('confirm')\n\nconst alertConfirmMessage = ref\u003Cnull | string>(null)\nconst trueBtnText = computed(() =>\n  modalType.value === 'confirm' ? 'Yes' : 'Okay',\n)\nconst falseBtnText = ref('No')\n\nfunction openModal(message: string, alertModal: boolean) {\n  alertConfirmMessage.value = message\n  modalType.value = alertModal ? 'alert' : 'confirm'\n\n  showConfirm.value = true\n\n  return new Promise((resolve) => {\n    resolvePromise = resolve\n  })\n}\n\nfunction handleUserInput(value: boolean) {\n  if (!resolvePromise) return\n\n  resolvePromise(value)\n  showConfirm.value = false\n}\n\ndefineExpose({ openModal })\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Ctransition name=\"fade-up\">\n    \u003Cdiv\n      v-if=\"showConfirm\"\n      class=\"alert-box\"\n    >\n      \u003Cdiv class=\"alert-box-header\">\n        {{ alertConfirmMessage }}\n      \u003C\u002Fdiv>\n      \u003Cdiv class=\"alert-box-buttons\">\n        \u003Ccommon-button\n          :button-text=\"trueBtnText\"\n          :primary=\"true\"\n          @click=\"handleUserInput(true)\"\n        >\n          \u003Ccheck-icon \u002F>\n        \u003C\u002Fcommon-button>\n        \u003Ccommon-button\n          v-if=\"modalType === 'confirm'\"\n          :button-text=\"falseBtnText\"\n          @click=\"handleUserInput(false)\"\n        >\n          \u003Ccross-icon \u002F>\n        \u003C\u002Fcommon-button>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Ftransition>\n\u003C\u002Ftemplate>\n",[116,4791,4792,4808,4822,4826,4838,4850,4862,4866,4884,4922,4926,4953,4957,4984,5001,5025,5029,5047,5051,5078,5088,5107,5111,5121,5125,5145,5155,5159,5163,5167,5184,5200,5204,5212,5221,5225,5229,5237,5245,5249,5257,5273,5280,5290,5300,5305,5322,5327,5336,5351,5359,5369,5379,5389,5394,5405,5415,5421,5431,5440,5449,5453,5462,5470,5478,5487,5495],{"__ignoreMap":114},[119,4793,4794,4796,4798,4800,4802,4804,4806],{"class":121,"line":122},[119,4795,134],{"class":133},[119,4797,3642],{"class":2462},[119,4799,3555],{"class":129},[119,4801,215],{"class":133},[119,4803,3649],{"class":585},[119,4805,3652],{"class":129},[119,4807,1848],{"class":133},[119,4809,4810,4813,4816,4819],{"class":121,"line":170},[119,4811,4812],{"class":125},"import",[119,4814,4815],{"class":133}," { ref, computed } ",[119,4817,4818],{"class":125},"from",[119,4820,4821],{"class":585}," 'vue'\n",[119,4823,4824],{"class":121,"line":185},[119,4825,1032],{"emptyLinePlaceholder":1031},[119,4827,4828,4830,4833,4835],{"class":121,"line":441},[119,4829,4812],{"class":125},[119,4831,4832],{"class":133}," CommonButton ",[119,4834,4818],{"class":125},[119,4836,4837],{"class":585}," '@\u002Fcomponents\u002FCommonButton.vue'\n",[119,4839,4840,4842,4845,4847],{"class":121,"line":452},[119,4841,4812],{"class":125},[119,4843,4844],{"class":133}," CheckIcon ",[119,4846,4818],{"class":125},[119,4848,4849],{"class":585}," '@\u002Fcomponents\u002Ficons\u002FIconCheck.vue'\n",[119,4851,4852,4854,4857,4859],{"class":121,"line":458},[119,4853,4812],{"class":125},[119,4855,4856],{"class":133}," CrossIcon ",[119,4858,4818],{"class":125},[119,4860,4861],{"class":585}," '@\u002Fcomponents\u002Ficons\u002FIconCancel.vue'\n",[119,4863,4864],{"class":121,"line":464},[119,4865,1032],{"emptyLinePlaceholder":1031},[119,4867,4868,4870,4873,4875,4878,4880,4882],{"class":121,"line":712},[119,4869,201],{"class":125},[119,4871,4872],{"class":163}," showConfirm",[119,4874,241],{"class":125},[119,4876,4877],{"class":129}," ref",[119,4879,329],{"class":133},[119,4881,1587],{"class":163},[119,4883,1022],{"class":133},[119,4885,4886,4888,4891,4893,4895,4897,4899,4902,4904,4906,4908,4911,4914,4917,4919],{"class":121,"line":902},[119,4887,4759],{"class":125},[119,4889,4890],{"class":129}," resolvePromise",[119,4892,147],{"class":125},[119,4894,574],{"class":133},[119,4896,629],{"class":143},[119,4898,147],{"class":125},[119,4900,4901],{"class":129}," PromiseLike",[119,4903,134],{"class":133},[119,4905,4767],{"class":163},[119,4907,1810],{"class":133},[119,4909,4910],{"class":125},"|",[119,4912,4913],{"class":163}," boolean",[119,4915,4916],{"class":133},") ",[119,4918,2919],{"class":125},[119,4920,4921],{"class":163}," void\n",[119,4923,4924],{"class":121,"line":908},[119,4925,1032],{"emptyLinePlaceholder":1031},[119,4927,4928,4930,4933,4935,4937,4939,4942,4944,4947,4949,4951],{"class":121,"line":1085},[119,4929,201],{"class":125},[119,4931,4932],{"class":163}," modalType",[119,4934,241],{"class":125},[119,4936,4877],{"class":129},[119,4938,134],{"class":133},[119,4940,4941],{"class":585},"'confirm'",[119,4943,160],{"class":125},[119,4945,4946],{"class":585}," 'alert'",[119,4948,140],{"class":133},[119,4950,4941],{"class":585},[119,4952,1022],{"class":133},[119,4954,4955],{"class":121,"line":1094},[119,4956,1032],{"emptyLinePlaceholder":1031},[119,4958,4959,4961,4964,4966,4968,4970,4973,4975,4978,4980,4982],{"class":121,"line":1101},[119,4960,201],{"class":125},[119,4962,4963],{"class":163}," alertConfirmMessage",[119,4965,241],{"class":125},[119,4967,4877],{"class":129},[119,4969,134],{"class":133},[119,4971,4972],{"class":163},"null",[119,4974,160],{"class":125},[119,4976,4977],{"class":163}," string",[119,4979,140],{"class":133},[119,4981,4972],{"class":163},[119,4983,1022],{"class":133},[119,4985,4986,4988,4991,4993,4996,4998],{"class":121,"line":1109},[119,4987,201],{"class":125},[119,4989,4990],{"class":163}," trueBtnText",[119,4992,241],{"class":125},[119,4994,4995],{"class":129}," computed",[119,4997,2916],{"class":133},[119,4999,5000],{"class":125},"=>\n",[119,5002,5003,5006,5008,5011,5014,5017,5020,5023],{"class":121,"line":1119},[119,5004,5005],{"class":133},"  modalType.value ",[119,5007,582],{"class":125},[119,5009,5010],{"class":585}," 'confirm'",[119,5012,5013],{"class":125}," ?",[119,5015,5016],{"class":585}," 'Yes'",[119,5018,5019],{"class":125}," :",[119,5021,5022],{"class":585}," 'Okay'",[119,5024,438],{"class":133},[119,5026,5027],{"class":121,"line":1124},[119,5028,1022],{"class":133},[119,5030,5031,5033,5036,5038,5040,5042,5045],{"class":121,"line":2843},[119,5032,201],{"class":125},[119,5034,5035],{"class":163}," falseBtnText",[119,5037,241],{"class":125},[119,5039,4877],{"class":129},[119,5041,329],{"class":133},[119,5043,5044],{"class":585},"'No'",[119,5046,1022],{"class":133},[119,5048,5049],{"class":121,"line":2848},[119,5050,1032],{"emptyLinePlaceholder":1031},[119,5052,5053,5055,5058,5060,5063,5065,5067,5069,5072,5074,5076],{"class":121,"line":2854},[119,5054,126],{"class":125},[119,5056,5057],{"class":129}," openModal",[119,5059,329],{"class":133},[119,5061,5062],{"class":143},"message",[119,5064,147],{"class":125},[119,5066,4977],{"class":163},[119,5068,417],{"class":133},[119,5070,5071],{"class":143},"alertModal",[119,5073,147],{"class":125},[119,5075,4913],{"class":163},[119,5077,505],{"class":133},[119,5079,5080,5083,5085],{"class":121,"line":2860},[119,5081,5082],{"class":133},"  alertConfirmMessage.value ",[119,5084,215],{"class":125},[119,5086,5087],{"class":133}," message\n",[119,5089,5090,5092,5094,5097,5100,5102,5104],{"class":121,"line":2866},[119,5091,5005],{"class":133},[119,5093,215],{"class":125},[119,5095,5096],{"class":133}," alertModal ",[119,5098,5099],{"class":125},"?",[119,5101,4946],{"class":585},[119,5103,5019],{"class":125},[119,5105,5106],{"class":585}," 'confirm'\n",[119,5108,5109],{"class":121,"line":2875},[119,5110,1032],{"emptyLinePlaceholder":1031},[119,5112,5113,5116,5118],{"class":121,"line":2880},[119,5114,5115],{"class":133},"  showConfirm.value ",[119,5117,215],{"class":125},[119,5119,5120],{"class":163}," true\n",[119,5122,5123],{"class":121,"line":2886},[119,5124,1032],{"emptyLinePlaceholder":1031},[119,5126,5127,5129,5131,5134,5137,5139,5141,5143],{"class":121,"line":2892},[119,5128,173],{"class":125},[119,5130,1006],{"class":125},[119,5132,5133],{"class":163}," Promise",[119,5135,5136],{"class":133},"((",[119,5138,4763],{"class":143},[119,5140,4916],{"class":133},[119,5142,2919],{"class":125},[119,5144,167],{"class":133},[119,5146,5147,5150,5152],{"class":121,"line":2898},[119,5148,5149],{"class":133},"    resolvePromise ",[119,5151,215],{"class":125},[119,5153,5154],{"class":133}," resolve\n",[119,5156,5157],{"class":121,"line":2904},[119,5158,2949],{"class":133},[119,5160,5161],{"class":121,"line":2910},[119,5162,188],{"class":133},[119,5164,5165],{"class":121,"line":2924},[119,5166,1032],{"emptyLinePlaceholder":1031},[119,5168,5169,5171,5174,5176,5178,5180,5182],{"class":121,"line":2935},[119,5170,126],{"class":125},[119,5172,5173],{"class":129}," handleUserInput",[119,5175,329],{"class":133},[119,5177,629],{"class":143},[119,5179,147],{"class":125},[119,5181,4913],{"class":163},[119,5183,505],{"class":133},[119,5185,5186,5189,5191,5194,5197],{"class":121,"line":2946},[119,5187,5188],{"class":125},"  if",[119,5190,574],{"class":133},[119,5192,5193],{"class":125},"!",[119,5195,5196],{"class":133},"resolvePromise) ",[119,5198,5199],{"class":125},"return\n",[119,5201,5202],{"class":121,"line":2952},[119,5203,1032],{"emptyLinePlaceholder":1031},[119,5205,5206,5209],{"class":121,"line":3885},[119,5207,5208],{"class":129},"  resolvePromise",[119,5210,5211],{"class":133},"(value)\n",[119,5213,5214,5216,5218],{"class":121,"line":3890},[119,5215,5115],{"class":133},[119,5217,215],{"class":125},[119,5219,5220],{"class":163}," false\n",[119,5222,5223],{"class":121,"line":3895},[119,5224,188],{"class":133},[119,5226,5227],{"class":121,"line":3912},[119,5228,1032],{"emptyLinePlaceholder":1031},[119,5230,5231,5234],{"class":121,"line":3921},[119,5232,5233],{"class":129},"defineExpose",[119,5235,5236],{"class":133},"({ openModal })\n",[119,5238,5239,5241,5243],{"class":121,"line":3926},[119,5240,2547],{"class":133},[119,5242,3642],{"class":2462},[119,5244,1848],{"class":133},[119,5246,5247],{"class":121,"line":3931},[119,5248,1032],{"emptyLinePlaceholder":1031},[119,5250,5251,5253,5255],{"class":121,"line":3948},[119,5252,134],{"class":133},[119,5254,2463],{"class":2462},[119,5256,1848],{"class":133},[119,5258,5259,5261,5263,5266,5268,5271],{"class":121,"line":3969},[119,5260,2470],{"class":133},[119,5262,2540],{"class":2462},[119,5264,5265],{"class":129}," name",[119,5267,215],{"class":133},[119,5269,5270],{"class":585},"\"fade-up\"",[119,5272,1848],{"class":133},[119,5274,5275,5277],{"class":121,"line":3974},[119,5276,2523],{"class":133},[119,5278,5279],{"class":2462},"div\n",[119,5281,5282,5285,5287],{"class":121,"line":3983},[119,5283,5284],{"class":129},"      v-if",[119,5286,215],{"class":133},[119,5288,5289],{"class":585},"\"showConfirm\"\n",[119,5291,5292,5295,5297],{"class":121,"line":3992},[119,5293,5294],{"class":129},"      class",[119,5296,215],{"class":133},[119,5298,5299],{"class":585},"\"alert-box\"\n",[119,5301,5302],{"class":121,"line":3997},[119,5303,5304],{"class":133},"    >\n",[119,5306,5307,5310,5312,5315,5317,5320],{"class":121,"line":4002},[119,5308,5309],{"class":133},"      \u003C",[119,5311,4457],{"class":2462},[119,5313,5314],{"class":129}," class",[119,5316,215],{"class":133},[119,5318,5319],{"class":585},"\"alert-box-header\"",[119,5321,1848],{"class":133},[119,5323,5324],{"class":121,"line":4007},[119,5325,5326],{"class":133},"        {{ alertConfirmMessage }}\n",[119,5328,5329,5332,5334],{"class":121,"line":4012},[119,5330,5331],{"class":133},"      \u003C\u002F",[119,5333,4457],{"class":2462},[119,5335,1848],{"class":133},[119,5337,5338,5340,5342,5344,5346,5349],{"class":121,"line":4019},[119,5339,5309],{"class":133},[119,5341,4457],{"class":2462},[119,5343,5314],{"class":129},[119,5345,215],{"class":133},[119,5347,5348],{"class":585},"\"alert-box-buttons\"",[119,5350,1848],{"class":133},[119,5352,5353,5356],{"class":121,"line":4024},[119,5354,5355],{"class":133},"        \u003C",[119,5357,5358],{"class":2462},"common-button\n",[119,5360,5361,5364,5366],{"class":121,"line":4035},[119,5362,5363],{"class":129},"          :button-text",[119,5365,215],{"class":133},[119,5367,5368],{"class":585},"\"trueBtnText\"\n",[119,5370,5371,5374,5376],{"class":121,"line":4044},[119,5372,5373],{"class":129},"          :primary",[119,5375,215],{"class":133},[119,5377,5378],{"class":585},"\"true\"\n",[119,5380,5381,5384,5386],{"class":121,"line":4053},[119,5382,5383],{"class":129},"          @click",[119,5385,215],{"class":133},[119,5387,5388],{"class":585},"\"handleUserInput(true)\"\n",[119,5390,5391],{"class":121,"line":4062},[119,5392,5393],{"class":133},"        >\n",[119,5395,5396,5399,5402],{"class":121,"line":4067},[119,5397,5398],{"class":133},"          \u003C",[119,5400,5401],{"class":2462},"check-icon",[119,5403,5404],{"class":133}," \u002F>\n",[119,5406,5407,5410,5413],{"class":121,"line":4072},[119,5408,5409],{"class":133},"        \u003C\u002F",[119,5411,5412],{"class":2462},"common-button",[119,5414,1848],{"class":133},[119,5416,5417,5419],{"class":121,"line":4081},[119,5418,5355],{"class":133},[119,5420,5358],{"class":2462},[119,5422,5423,5426,5428],{"class":121,"line":4086},[119,5424,5425],{"class":129},"          v-if",[119,5427,215],{"class":133},[119,5429,5430],{"class":585},"\"modalType === 'confirm'\"\n",[119,5432,5433,5435,5437],{"class":121,"line":4095},[119,5434,5363],{"class":129},[119,5436,215],{"class":133},[119,5438,5439],{"class":585},"\"falseBtnText\"\n",[119,5441,5442,5444,5446],{"class":121,"line":4102},[119,5443,5383],{"class":129},[119,5445,215],{"class":133},[119,5447,5448],{"class":585},"\"handleUserInput(false)\"\n",[119,5450,5451],{"class":121,"line":4111},[119,5452,5393],{"class":133},[119,5454,5455,5457,5460],{"class":121,"line":4120},[119,5456,5398],{"class":133},[119,5458,5459],{"class":2462},"cross-icon",[119,5461,5404],{"class":133},[119,5463,5464,5466,5468],{"class":121,"line":4129},[119,5465,5409],{"class":133},[119,5467,5412],{"class":2462},[119,5469,1848],{"class":133},[119,5471,5472,5474,5476],{"class":121,"line":4138},[119,5473,5331],{"class":133},[119,5475,4457],{"class":2462},[119,5477,1848],{"class":133},[119,5479,5480,5483,5485],{"class":121,"line":4143},[119,5481,5482],{"class":133},"    \u003C\u002F",[119,5484,4457],{"class":2462},[119,5486,1848],{"class":133},[119,5488,5489,5491,5493],{"class":121,"line":4154},[119,5490,2537],{"class":133},[119,5492,2540],{"class":2462},[119,5494,1848],{"class":133},[119,5496,5497,5499,5501],{"class":121,"line":4163},[119,5498,2547],{"class":133},[119,5500,2463],{"class":2462},[119,5502,1848],{"class":133},[11,5504,5505,5506,5508,5509,5511,5512,5514,5515,35],{},"I have two buttons inside the component: one returns ",[116,5507,1577],{}," when clicked and the other returns ",[116,5510,1587],{},". The false-returning button is hidden when ",[116,5513,4701],{}," is ",[116,5516,4709],{},[2638,5518,5520],{"id":5519},"openmodal",[116,5521,5522],{},"openModal",[11,5524,5525,5526,5528,5529,5531,5532,5534,5535,5531,5537,5539,5540,5542,5543,5545],{},"This function takes two arguments: the message to display, and a Boolean—if ",[116,5527,1577],{},", we set ",[116,5530,4701],{}," to ",[116,5533,4709],{},". At the start we set ",[116,5536,4691],{},[116,5538,1577],{},", set ",[116,5541,4723],{}," to the first argument, and update ",[116,5544,4701],{}," from the second argument when needed.",[11,5547,5548,5549,5552,5553,5555,5556,5558,5559,5561,5562,5564,5565,5567,5568,5570,5571,5573],{},"After that we return a new ",[116,5550,5551],{},"Promise",", and inside the executor we assign the ",[116,5554,4763],{}," function to the ",[116,5557,4755],{}," variable declared earlier. We don’t call ",[116,5560,4763],{}," inside this component for the open path. Instead we expose ",[116,5563,5522],{}," with ",[116,5566,5233],{}," so parent components can call it and ",[116,5569,4598],{}," the user’s response. We can use ",[116,5572,4598],{}," because we’re returning a Promise.",[2638,5575,5577],{"id":5576},"handleuserinput",[116,5578,5579],{},"handleUserInput",[11,5581,5582,5583,4706,5585,5587,5588,5590,5591,5593,5594,5596,5597,5531,5599,5601],{},"When the user clicks a button inside the modal, we call this function with ",[116,5584,1577],{},[116,5586,1587],{},"—",[116,5589,1577],{}," for the true button, ",[116,5592,1587],{}," for the false button (hidden in alert mode). Inside the function we check that ",[116,5595,4755],{}," is defined (to keep TypeScript happy), call it with the boolean we received, then set ",[116,5598,4691],{},[116,5600,1587],{}," to close the modal.",[11,5603,5604,5606,5607,5514,5609,5611,5612,5614,5615,5617,5618,5620,5621,35],{},[116,5605,5579],{}," only runs when ",[116,5608,4691],{},[116,5610,1577],{},", and that only happens after ",[116,5613,5522],{}," has been called—so ",[116,5616,4755],{}," will already hold the ",[116,5619,4763],{}," from the Promise returned by ",[116,5622,5522],{},[92,5624,5626],{"id":5625},"using-alertconfirm-inside-other-components","Using AlertConfirm inside other components",[11,5628,5629],{},"Follow these steps:",[2384,5631,5632,5635,5640],{},[52,5633,5634],{},"Import the component.",[52,5636,5637,5638,2655],{},"Add it to your template, and bind a template ref (for example ",[116,5639,4602],{},[52,5641,5642],{},"When you want to open the modal:",[109,5644,5646],{"className":111,"code":5645,"language":113,"meta":114,"style":114},"\u002F\u002F Alert (one button)\nawait alertConfirm.value?.openModal('This will be an alert', true)\n\n\u002F\u002F Confirm (Yes \u002F No)\nawait alertConfirm.value?.openModal('This will be a confirm')\n",[116,5647,5648,5653,5673,5677,5682],{"__ignoreMap":114},[119,5649,5650],{"class":121,"line":122},[119,5651,5652],{"class":251},"\u002F\u002F Alert (one button)\n",[119,5654,5655,5657,5660,5662,5664,5667,5669,5671],{"class":121,"line":170},[119,5656,4598],{"class":125},[119,5658,5659],{"class":133}," alertConfirm.value?.",[119,5661,5522],{"class":129},[119,5663,329],{"class":133},[119,5665,5666],{"class":585},"'This will be an alert'",[119,5668,417],{"class":133},[119,5670,1577],{"class":163},[119,5672,1022],{"class":133},[119,5674,5675],{"class":121,"line":185},[119,5676,1032],{"emptyLinePlaceholder":1031},[119,5678,5679],{"class":121,"line":441},[119,5680,5681],{"class":251},"\u002F\u002F Confirm (Yes \u002F No)\n",[119,5683,5684,5686,5688,5690,5692,5695],{"class":121,"line":452},[119,5685,4598],{"class":125},[119,5687,5659],{"class":133},[119,5689,5522],{"class":129},[119,5691,329],{"class":133},[119,5693,5694],{"class":585},"'This will be a confirm'",[119,5696,1022],{"class":133},[11,5698,5699,5700,5703],{},"Here’s how I wired it in ",[116,5701,5702],{},"App.vue","—two buttons, one for alert and one for confirm:",[109,5705,5707],{"className":2451,"code":5706,"language":2453,"meta":114,"style":114},"\u003Cscript lang=\"ts\" setup>\nimport { ref } from 'vue'\n\nimport CommonButton from '.\u002Fcomponents\u002FCommonButton.vue'\nimport AlertConfirmModal from '.\u002Fcomponents\u002FAlertConfirmModal.vue'\n\nconst alertConfirm = ref\u003CInstanceType\u003Ctypeof AlertConfirmModal> | null>(null)\n\nasync function openAlertConfirm(alertModal = false) {\n  const alertMessage =\n    'Hi!, You created a custom async alert modal. This was amazing.'\n\n  const confirmMessage = 'It was quite interesting and elegant right?'\n\n  const userInput = await alertConfirm.value?.openModal(\n    alertModal ? alertMessage : confirmMessage,\n    alertModal,\n  )\n\n  console.log('This was the user input', userInput)\n}\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv class=\"buttons-wrapper\">\n    \u003CCommonButton\n      button-text=\"Open Alert\"\n      :primary=\"true\"\n      @click=\"openAlertConfirm(true)\"\n    \u002F>\n    \u003CCommonButton\n      button-text=\"Open Confirm\"\n      :primary=\"true\"\n      @click=\"openAlertConfirm(false)\"\n    \u002F>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"alert-modal\">\n    \u003CAlertConfirmModal ref=\"alertConfirm\" \u002F>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[116,5708,5709,5725,5736,5740,5751,5763,5767,5801,5805,5827,5836,5841,5845,5857,5861,5879,5894,5899,5903,5907,5921,5925,5933,5937,5945,5960,5967,5977,5994,6017,6022,6028,6037,6051,6071,6075,6083,6098,6114,6122],{"__ignoreMap":114},[119,5710,5711,5713,5715,5717,5719,5721,5723],{"class":121,"line":122},[119,5712,134],{"class":133},[119,5714,3642],{"class":2462},[119,5716,3555],{"class":129},[119,5718,215],{"class":133},[119,5720,3649],{"class":585},[119,5722,3652],{"class":129},[119,5724,1848],{"class":133},[119,5726,5727,5729,5732,5734],{"class":121,"line":170},[119,5728,4812],{"class":125},[119,5730,5731],{"class":133}," { ref } ",[119,5733,4818],{"class":125},[119,5735,4821],{"class":585},[119,5737,5738],{"class":121,"line":185},[119,5739,1032],{"emptyLinePlaceholder":1031},[119,5741,5742,5744,5746,5748],{"class":121,"line":441},[119,5743,4812],{"class":125},[119,5745,4832],{"class":133},[119,5747,4818],{"class":125},[119,5749,5750],{"class":585}," '.\u002Fcomponents\u002FCommonButton.vue'\n",[119,5752,5753,5755,5758,5760],{"class":121,"line":452},[119,5754,4812],{"class":125},[119,5756,5757],{"class":133}," AlertConfirmModal ",[119,5759,4818],{"class":125},[119,5761,5762],{"class":585}," '.\u002Fcomponents\u002FAlertConfirmModal.vue'\n",[119,5764,5765],{"class":121,"line":458},[119,5766,1032],{"emptyLinePlaceholder":1031},[119,5768,5769,5771,5774,5776,5778,5780,5783,5785,5787,5790,5792,5795,5797,5799],{"class":121,"line":464},[119,5770,201],{"class":125},[119,5772,5773],{"class":163}," alertConfirm",[119,5775,241],{"class":125},[119,5777,4877],{"class":129},[119,5779,134],{"class":133},[119,5781,5782],{"class":129},"InstanceType",[119,5784,134],{"class":133},[119,5786,577],{"class":125},[119,5788,5789],{"class":133}," AlertConfirmModal> ",[119,5791,4910],{"class":125},[119,5793,5794],{"class":163}," null",[119,5796,140],{"class":133},[119,5798,4972],{"class":163},[119,5800,1022],{"class":133},[119,5802,5803],{"class":121,"line":712},[119,5804,1032],{"emptyLinePlaceholder":1031},[119,5806,5807,5810,5813,5816,5818,5820,5822,5825],{"class":121,"line":902},[119,5808,5809],{"class":125},"async",[119,5811,5812],{"class":125}," function",[119,5814,5815],{"class":129}," openAlertConfirm",[119,5817,329],{"class":133},[119,5819,5071],{"class":143},[119,5821,241],{"class":125},[119,5823,5824],{"class":163}," false",[119,5826,505],{"class":133},[119,5828,5829,5831,5834],{"class":121,"line":908},[119,5830,2684],{"class":125},[119,5832,5833],{"class":163}," alertMessage",[119,5835,792],{"class":125},[119,5837,5838],{"class":121,"line":1085},[119,5839,5840],{"class":585},"    'Hi!, You created a custom async alert modal. This was amazing.'\n",[119,5842,5843],{"class":121,"line":1094},[119,5844,1032],{"emptyLinePlaceholder":1031},[119,5846,5847,5849,5852,5854],{"class":121,"line":1101},[119,5848,2684],{"class":125},[119,5850,5851],{"class":163}," confirmMessage",[119,5853,241],{"class":125},[119,5855,5856],{"class":585}," 'It was quite interesting and elegant right?'\n",[119,5858,5859],{"class":121,"line":1109},[119,5860,1032],{"emptyLinePlaceholder":1031},[119,5862,5863,5865,5868,5870,5873,5875,5877],{"class":121,"line":1119},[119,5864,2684],{"class":125},[119,5866,5867],{"class":163}," userInput",[119,5869,241],{"class":125},[119,5871,5872],{"class":125}," await",[119,5874,5659],{"class":133},[119,5876,5522],{"class":129},[119,5878,1496],{"class":133},[119,5880,5881,5884,5886,5889,5891],{"class":121,"line":1124},[119,5882,5883],{"class":133},"    alertModal ",[119,5885,5099],{"class":125},[119,5887,5888],{"class":133}," alertMessage ",[119,5890,147],{"class":125},[119,5892,5893],{"class":133}," confirmMessage,\n",[119,5895,5896],{"class":121,"line":2843},[119,5897,5898],{"class":133},"    alertModal,\n",[119,5900,5901],{"class":121,"line":2848},[119,5902,709],{"class":133},[119,5904,5905],{"class":121,"line":2854},[119,5906,1032],{"emptyLinePlaceholder":1031},[119,5908,5909,5911,5913,5915,5918],{"class":121,"line":2860},[119,5910,593],{"class":133},[119,5912,596],{"class":129},[119,5914,329],{"class":133},[119,5916,5917],{"class":585},"'This was the user input'",[119,5919,5920],{"class":133},", userInput)\n",[119,5922,5923],{"class":121,"line":2866},[119,5924,188],{"class":133},[119,5926,5927,5929,5931],{"class":121,"line":2875},[119,5928,2547],{"class":133},[119,5930,3642],{"class":2462},[119,5932,1848],{"class":133},[119,5934,5935],{"class":121,"line":2880},[119,5936,1032],{"emptyLinePlaceholder":1031},[119,5938,5939,5941,5943],{"class":121,"line":2886},[119,5940,134],{"class":133},[119,5942,2463],{"class":2462},[119,5944,1848],{"class":133},[119,5946,5947,5949,5951,5953,5955,5958],{"class":121,"line":2892},[119,5948,2470],{"class":133},[119,5950,4457],{"class":2462},[119,5952,5314],{"class":129},[119,5954,215],{"class":133},[119,5956,5957],{"class":585},"\"buttons-wrapper\"",[119,5959,1848],{"class":133},[119,5961,5962,5964],{"class":121,"line":2898},[119,5963,2523],{"class":133},[119,5965,5966],{"class":2462},"CommonButton\n",[119,5968,5969,5972,5974],{"class":121,"line":2904},[119,5970,5971],{"class":129},"      button-text",[119,5973,215],{"class":133},[119,5975,5976],{"class":585},"\"Open Alert\"\n",[119,5978,5979,5981,5984,5986,5989,5991],{"class":121,"line":2910},[119,5980,1924],{"class":133},[119,5982,5983],{"class":129},"primary",[119,5985,215],{"class":133},[119,5987,5988],{"class":585},"\"",[119,5990,1577],{"class":163},[119,5992,5993],{"class":585},"\"\n",[119,5995,5996,5999,6002,6004,6006,6009,6011,6013,6015],{"class":121,"line":2924},[119,5997,5998],{"class":133},"      @",[119,6000,6001],{"class":129},"click",[119,6003,215],{"class":133},[119,6005,5988],{"class":585},[119,6007,6008],{"class":129},"openAlertConfirm",[119,6010,329],{"class":133},[119,6012,1577],{"class":163},[119,6014,636],{"class":133},[119,6016,5993],{"class":585},[119,6018,6019],{"class":121,"line":2935},[119,6020,6021],{"class":133},"    \u002F>\n",[119,6023,6024,6026],{"class":121,"line":2946},[119,6025,2523],{"class":133},[119,6027,5966],{"class":2462},[119,6029,6030,6032,6034],{"class":121,"line":2952},[119,6031,5971],{"class":129},[119,6033,215],{"class":133},[119,6035,6036],{"class":585},"\"Open Confirm\"\n",[119,6038,6039,6041,6043,6045,6047,6049],{"class":121,"line":3885},[119,6040,1924],{"class":133},[119,6042,5983],{"class":129},[119,6044,215],{"class":133},[119,6046,5988],{"class":585},[119,6048,1577],{"class":163},[119,6050,5993],{"class":585},[119,6052,6053,6055,6057,6059,6061,6063,6065,6067,6069],{"class":121,"line":3890},[119,6054,5998],{"class":133},[119,6056,6001],{"class":129},[119,6058,215],{"class":133},[119,6060,5988],{"class":585},[119,6062,6008],{"class":129},[119,6064,329],{"class":133},[119,6066,1587],{"class":163},[119,6068,636],{"class":133},[119,6070,5993],{"class":585},[119,6072,6073],{"class":121,"line":3895},[119,6074,6021],{"class":133},[119,6076,6077,6079,6081],{"class":121,"line":3912},[119,6078,2537],{"class":133},[119,6080,4457],{"class":2462},[119,6082,1848],{"class":133},[119,6084,6085,6087,6089,6091,6093,6096],{"class":121,"line":3921},[119,6086,2470],{"class":133},[119,6088,4457],{"class":2462},[119,6090,5314],{"class":129},[119,6092,215],{"class":133},[119,6094,6095],{"class":585},"\"alert-modal\"",[119,6097,1848],{"class":133},[119,6099,6100,6102,6105,6107,6109,6112],{"class":121,"line":3926},[119,6101,2523],{"class":133},[119,6103,6104],{"class":2462},"AlertConfirmModal",[119,6106,4877],{"class":129},[119,6108,215],{"class":133},[119,6110,6111],{"class":585},"\"alertConfirm\"",[119,6113,5404],{"class":133},[119,6115,6116,6118,6120],{"class":121,"line":3931},[119,6117,2537],{"class":133},[119,6119,4457],{"class":2462},[119,6121,1848],{"class":133},[119,6123,6124,6126,6128],{"class":121,"line":3948},[119,6125,2547],{"class":133},[119,6127,2463],{"class":2462},[119,6129,1848],{"class":133},[11,6131,6132,6133,35],{},"And that’s it—you have a way to write alert and confirm modals that you can ",[116,6134,4598],{},[11,6136,6137,6138,35],{},"If you want the full project, it’s on GitHub: ",[21,6139,4656],{"href":4654,"rel":6140},[33],[11,6142,6143],{},"Thanks for reading—see you next time.",[2296,6145,6146],{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":114,"searchDepth":170,"depth":170,"links":6148},[6149,6150,6155],{"id":4633,"depth":170,"text":4634},{"id":4662,"depth":170,"text":4663,"children":6151},[6152,6153,6154],{"id":4680,"depth":185,"text":4681},{"id":5519,"depth":185,"text":5522},{"id":5576,"depth":185,"text":5579},{"id":5625,"depth":170,"text":5626},"2022-11-07","Build a Vue 3 AlertConfirm modal that returns a Promise so you can await the user’s Yes\u002FNo or Okay response—useful in route guards and other in-function confirmations.",{"src":6159,"alt":6160},"\u002Fimages\u002Fblog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3-cover.jpg","Vue-themed cover showing function execution pausing for an alert or confirm modal, then continuing after the user responds",{},"\u002Fblog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3",{"title":4580,"description":6157},"blog\u002Fcreating-a-customized-alert-and-confirm-modal-in-vue-3",[4575,6166,2329,6167,6168],"Vue","Promises","Asyncawait",null,"DiFFuqyErLXVNcKD0X2TjVPLqn2FhqwhO6Ud_JVyrzY",{"id":6172,"title":6173,"body":6174,"description":6427,"extension":2319,"meta":6428,"navigation":1031,"path":6429,"seo":6430,"stem":6431,"__hash__":6432},"pages\u002Fprivacy-policy.md","Privacy Policy",{"type":8,"value":6175,"toc":6413},[6176,6181,6184,6187,6191,6200,6203,6223,6226,6229,6232,6249,6253,6256,6259,6263,6266,6281,6285,6292,6301,6304,6311,6315,6318,6321,6325,6328,6331,6335,6338,6341,6344,6348,6355,6358,6362,6365,6368,6372,6375,6378,6381,6384,6388,6391,6395,6398],[11,6177,6178],{},[4687,6179,6180],{},"Last updated: December 5, 2026",[11,6182,6183],{},"I respect your privacy. This website is my personal portfolio and technical blog, operated by Akshat Trivedi in India. Its purpose is to share my work, technical articles, projects, and professional experience.",[11,6185,6186],{},"This Privacy Policy explains what information is processed when you visit this website, why it is used, and the choices available to you.",[92,6188,6190],{"id":6189},"_1-website-analytics","1. Website analytics",[11,6192,6193,6194,6199],{},"This website uses ",[21,6195,6198],{"href":6196,"rel":6197},"https:\u002F\u002Fumami.is\u002F",[33],"Umami",", a privacy-focused web analytics platform, to understand how visitors discover and interact with its content.",[11,6201,6202],{},"Depending on the analytics configuration, Umami may collect:",[49,6204,6205,6208,6211,6214,6217,6220],{},[52,6206,6207],{},"Pages visited and page titles.",[52,6209,6210],{},"Visit timestamps, session duration, and navigation patterns.",[52,6212,6213],{},"Referring websites and campaign information, such as UTM parameters.",[52,6215,6216],{},"Browser, operating system, device type, screen size, and language.",[52,6218,6219],{},"Approximate geographical information, such as country, region, or city.",[52,6221,6222],{},"Basic interaction events, such as clicks on links or buttons, where enabled.",[11,6224,6225],{},"I use this information to understand which articles are useful, measure website traffic, identify content and usability improvements, and evaluate the effectiveness of content shared on other platforms.",[11,6227,6228],{},"Umami's standard analytics tracker does not use tracking cookies. It may process your IP address and browser information to estimate location and generate a pseudonymous visitor or session identifier. Raw IP addresses are not stored as fields in standard Umami analytics records, although infrastructure providers may process or log them for operational and security purposes.",[11,6230,6231],{},"I do not use analytics to build advertising profiles, track you across unrelated websites, or intentionally collect your name, email address, or other directly identifying information. Google Analytics is no longer used on this website.",[11,6233,6234,6235,417,6240,2633,6245,35],{},"For further information, see ",[21,6236,6239],{"href":6237,"rel":6238},"https:\u002F\u002Fdocs.umami.is\u002Fdocs\u002Ffaq",[33],"Umami's documentation",[21,6241,6244],{"href":6242,"rel":6243},"https:\u002F\u002Fdocs.umami.is\u002Fdocs\u002Fmetric-definitions",[33],"metric definitions",[21,6246,6173],{"href":6247,"rel":6248},"https:\u002F\u002Fumami.is\u002Fprivacy",[33],[92,6250,6252],{"id":6251},"_2-cookies-and-local-storage","2. Cookies and local storage",[11,6254,6255],{},"This website does not use analytics cookies. Browser storage may be used to remember functional preferences, such as your selected light or dark theme.",[11,6257,6258],{},"These preferences are intended to improve your browsing experience, not to identify you or track your activity across websites. You can clear locally stored preferences through your browser settings.",[92,6260,6262],{"id":6261},"_3-website-hosting-and-security","3. Website hosting and security",[11,6264,6265],{},"This website is hosted on GitHub Pages. GitHub may collect technical information, including IP addresses and request logs, to deliver the website, maintain its infrastructure, and protect its services against abuse and security threats.",[11,6267,6268,6269,6274,6275,6280],{},"GitHub handles this information in accordance with its own ",[21,6270,6273],{"href":6271,"rel":6272},"https:\u002F\u002Fdocs.github.com\u002Fen\u002Fsite-policy\u002Fprivacy-policies\u002Fgithub-general-privacy-statement",[33],"Privacy Statement",". Its ",[21,6276,6279],{"href":6277,"rel":6278},"https:\u002F\u002Fdocs.github.com\u002Fen\u002Fpages\u002Fgetting-started-with-github-pages\u002Fwhat-is-github-pages",[33],"GitHub Pages documentation"," also explains its visitor IP logging practices.",[92,6282,6284],{"id":6283},"_4-community-chess-feature","4. Community chess feature",[11,6286,6287,6288,6291],{},"When the optional ",[4687,6289,6290],{},"Your Move"," section is enabled, your browser may request the current shared game and cumulative results, and may submit Black moves, through a Supabase-hosted API (Edge Function and Postgres database).",[11,6293,6294,6295,6300],{},"That service processes the technical information needed to operate the shared game, such as request metadata and move payloads (for example the selected squares and revision checks). The public site does not create a chess account for you. Infrastructure providers such as ",[21,6296,6299],{"href":6297,"rel":6298},"https:\u002F\u002Fsupabase.com\u002F",[33],"Supabase"," may also process IP addresses and request logs for delivery, security, and abuse prevention, according to their own policies. I do not intentionally store visitor IP addresses in the chess game database for profiling.",[11,6302,6303],{},"I do not use chess feature requests to build advertising profiles, track you across unrelated websites, or intentionally collect your name, email address, or other directly identifying information through this feature. No account is required to view the board or attempt a community move.",[11,6305,6234,6306,35],{},[21,6307,6310],{"href":6308,"rel":6309},"https:\u002F\u002Fsupabase.com\u002Fprivacy",[33],"Supabase's Privacy Policy",[92,6312,6314],{"id":6313},"_5-contact-and-communications","5. Contact and communications",[11,6316,6317],{},"If you voluntarily contact me by email or through a linked professional platform, I may receive information you choose to share, such as your name, email address, and message.",[11,6319,6320],{},"I use that information to respond to your enquiry and, where relevant, continue the conversation. I do not intentionally add your contact information to marketing lists without your permission.",[92,6322,6324],{"id":6323},"_6-legal-bases-for-processing","6. Legal bases for processing",[11,6326,6327],{},"Where applicable data protection law requires a legal basis, I rely on legitimate interests for necessary website operation, security, privacy-conscious audience measurement, and operating the optional shared chess feature, where permitted and where those interests are not overridden by your rights. I process correspondence to respond to your requests and may process information to comply with legal obligations.",[11,6329,6330],{},"Where consent is required by applicable law, processing that requires consent will take place only after it has been obtained. You may withdraw that consent at any time.",[92,6332,6334],{"id":6333},"_7-sharing-and-international-processing","7. Sharing and international processing",[11,6336,6337],{},"I do not sell or rent visitor information, or share it for targeted advertising.",[11,6339,6340],{},"Information may be processed by hosting, analytics, and chess-feature service providers for the purposes described in this policy, or disclosed where necessary to comply with a legal obligation or protect the security of the website.",[11,6342,6343],{},"The website and its service providers may process information outside your country of residence. Where applicable, international transfers of personal information are subject to the safeguards required by relevant data protection law.",[92,6345,6347],{"id":6346},"_8-data-retention","8. Data retention",[11,6349,6350,6351,6354],{},"Analytics records are retained for ",[4687,6352,6353],{},"6 months",", subject to the configured retention settings and any applicable backup or legal retention requirements.",[11,6356,6357],{},"Information received through correspondence is retained for as long as reasonably necessary to address the enquiry, maintain relevant records, or comply with legal obligations. Infrastructure logs and chess-feature operational data are retained according to the relevant provider's policies and the technical needs of the shared game.",[92,6359,6361],{"id":6360},"_9-external-links","9. External links",[11,6363,6364],{},"This website may contain links to external websites, including GitHub, LinkedIn, Medium, X (formerly Twitter), Chess.com, and technical documentation.",[11,6366,6367],{},"Once you follow an external link, the destination website's own privacy practices apply. I do not control the information collected by those websites and encourage you to review their respective privacy policies.",[92,6369,6371],{"id":6370},"_10-your-privacy-choices-and-rights","10. Your privacy choices and rights",[11,6373,6374],{},"You can use browser privacy settings or content-blocking extensions to prevent analytics requests and clear locally stored website preferences. If you do not want the chess feature to send requests from your browser, leave the section unused or avoid enabling a live chess build.",[11,6376,6377],{},"Depending on the laws applicable to you, you may also have the right to request access to, correction of, or deletion of personal information; restrict or object to certain processing; withdraw consent; request portability of eligible data; or raise a complaint with the relevant data protection authority.",[11,6379,6380],{},"Because standard website analytics are not linked to your name or email address, I may not be able to identify individual analytics records associated with you. I will not collect additional identifying information solely to identify an otherwise unidentifiable analytics record unless required by law.",[11,6382,6383],{},"To exercise your applicable rights or raise a privacy concern, please use the contact details below.",[92,6385,6387],{"id":6386},"_11-changes-to-this-policy","11. Changes to this policy",[11,6389,6390],{},"I may update this Privacy Policy as the website, its features, or applicable privacy requirements change. The latest version will be available on this page, with the date of the most recent update shown at the top.",[92,6392,6394],{"id":6393},"_12-contact","12. Contact",[11,6396,6397],{},"If you have questions about this Privacy Policy, how information is handled, or your privacy rights, please contact:",[11,6399,6400,6403,6406,6407],{},[4687,6401,6402],{},"Akshat Trivedi",[6404,6405],"br",{},"\nEmail: ",[4687,6408,6409],{},[21,6410,6412],{"href":6411},"mailto:akshattriv.iit@gmail.com","akshattriv.iit@gmail.com",{"title":114,"searchDepth":170,"depth":170,"links":6414},[6415,6416,6417,6418,6419,6420,6421,6422,6423,6424,6425,6426],{"id":6189,"depth":170,"text":6190},{"id":6251,"depth":170,"text":6252},{"id":6261,"depth":170,"text":6262},{"id":6283,"depth":170,"text":6284},{"id":6313,"depth":170,"text":6314},{"id":6323,"depth":170,"text":6324},{"id":6333,"depth":170,"text":6334},{"id":6346,"depth":170,"text":6347},{"id":6360,"depth":170,"text":6361},{"id":6370,"depth":170,"text":6371},{"id":6386,"depth":170,"text":6387},{"id":6393,"depth":170,"text":6394},"Learn how this website handles visitor information and uses privacy-focused analytics.",{},"\u002Fprivacy-policy",{"title":6173,"description":6427},"privacy-policy","hbDoZ5oCU6k6QGr5BOrwcj0b6QxC79DpJI1U1j11rOM",1796414207479]