2:I[8000,["576","static/chunks/576-ca9d6d6dcb1419bc.js","986","static/chunks/986-de568bb4a9a5e8b9.js","308","static/chunks/app/blog/%5Bslug%5D/page-8c6bdf8301646b8b.js"],"default"] 4:I[6102,[],""] 6:I[2609,[],""] 7:I[885,["717","static/chunks/b8bc3934-ee45afae3256a18f.js","404","static/chunks/43abe07a-b2dc54c2320d6a3e.js","576","static/chunks/576-ca9d6d6dcb1419bc.js","986","static/chunks/986-de568bb4a9a5e8b9.js","185","static/chunks/app/layout-c32b7cdbec41233c.js"],"default"] 8:I[6196,["576","static/chunks/576-ca9d6d6dcb1419bc.js","986","static/chunks/986-de568bb4a9a5e8b9.js","308","static/chunks/app/blog/%5Bslug%5D/page-8c6bdf8301646b8b.js"],""] 9:I[5619,["717","static/chunks/b8bc3934-ee45afae3256a18f.js","404","static/chunks/43abe07a-b2dc54c2320d6a3e.js","576","static/chunks/576-ca9d6d6dcb1419bc.js","986","static/chunks/986-de568bb4a9a5e8b9.js","185","static/chunks/app/layout-c32b7cdbec41233c.js"],"default"] 5:["slug","exploring-the-power-of-static-typing","d"] 0:["jJX8gC_fpWuPRZPjXcR-X",[[["",{"children":["blog",{"children":[["slug","exploring-the-power-of-static-typing","d"],{"children":["__PAGE__?{\"slug\":\"exploring-the-power-of-static-typing\"}",{}]}]}]},"$undefined","$undefined",true],["",{"children":["blog",{"children":[["slug","exploring-the-power-of-static-typing","d"],{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"title":"Exploring the power of static typing","children":[["$","script",null,{"type":"application/ld+json","suppressHydrationWarning":true,"dangerouslySetInnerHTML":{"__html":"{\"@context\":\"https://schema.org\",\"@type\":\"BlogPosting\",\"headline\":\"Exploring the power of static typing\",\"datePublished\":\"2022-06-07\",\"dateModified\":\"2022-06-07\",\"description\":\"There's a long debate about static and dynamic typing in the world of software. But, I think static typing is superior.\",\"url\":\"https://aelpxy.dev/blog/exploring-the-power-of-static-typing\",\"author\":{\"@type\":\"Person\",\"name\":\"aelpxy\"}}"}}],["$","h2",null,{"className":"text-xl py-6 tracking-tighter text-stone-100 font-mono","children":[["$","span",null,{"className":"select-none","children":"`"}],"/blog/","exploring-the-power-of-static-typing",["$","span",null,{"className":"select-none","children":"`"}]]}],["$","div",null,{"className":"flex justify-between items-center mb-8 text-sm","children":["$","p",null,{"className":"text-sm text-stone-400","children":"June 7, 2022"}]}],["$","article",null,{"className":"prose","children":"$L3"}]]}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","blog","children","$5","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","blog","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/70ecd251ff2c2a46.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_4b8806 __variable_d94f73 selection:text-stone-900 selection:bg-stone-100 min-h-screen antialiased","children":[["$","$L7",null,{}],["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":["$","$L2",null,{"title":"404","children":["$","div",null,{"children":[["$","h1",null,{"className":"text-2xl py-6 font-semibold","children":"The page you requested was not found."}],["$","div",null,{"className":"mt-10"}],["$","$L8",null,{"href":"/","className":"hover:bg-stone-900 hover:text-stone-300 transition-all duration-300 ease-in-out p-2 rounded-xl border border-stone-800","children":"Return to home"}]]}]}],"notFoundStyles":[]}],["$","$L9",null,{}]]}]}]],null],null],["$La",null]]]] 3:[["$","h2",null,{"id":"why-should-you-care","children":[["$","a","link-why-should-you-care",{"href":"#why-should-you-care","className":"anchor"}],"Why should you care?"]}],"\n",["$","p",null,{"children":"The developers who write dynamic languages always argue how easy it is to get\nstarted. However, once they start using statically typed languages, it's\nactually hard for them get back into dynamic languages. Languages like\nJavaScript, Python (Python has Typehints for typesafety), and many others don't\ncare about type safety and thus can throw really bad runtime errors if not\nhandled correctly."}],"\n",["$","p",null,{"children":"While TypeScript is indeed a superset of JavaScript, it does type checking\nduring compile time, which in fact reduces the chances of a runtime error.\nModern languages like Rust and Go focus strictly on type safety (PS. Go isn't as\nstrict as Rust)."}],"\n",["$","p",null,{"children":"If you want to build solid software, static languages should be considered.\nWhile many may argue that a lot of companies are using dynamic languages, and I\nagree with them, they in fact do, but why would you want to waste time debugging\ninstead of just catching it during development? Doesn't it save more time than\nhaving to debug in production?"}],"\n",["$","h2",null,{"id":"preventing-errors","children":[["$","a","link-preventing-errors",{"href":"#preventing-errors","className":"anchor"}],"Preventing errors"]}],"\n",["$","p",null,{"children":"One of the benefits of static typing is its ability to catch errors during the\ndevelopment time, rather than at runtime. In dynamically typed languages, it's\npossible to write code that compiles and runs without any issues, only to\nencounter unexpected errors at runtime due to type mismatches or other issues.\nThis can lead to frustrating debugging sessions and costly production issues.\nWith static typing, the compiler can perform type checking during the\ncompilation, identifying and reporting these types of errors before the code is\neven executed. This allows to address problems early in the development process,\nsaving time and reducing the risk of bugs making it to production."}],"\n",["$","p",null,{"children":"The problem:"}],"\n","$Lb","\n",["$","p",null,{"children":"Everything looks fine, right? So, where's the issue? The issue is that you don't\nknow what the function returns. This may not be an issue in small projects, but\nonce you dive deeper into larger projects, this will become a headache."}],"\n",["$","p",null,{"children":"The solution:"}],"\n","$Lc","\n",["$","p",null,{"children":"Perhaps that looks like a lot but if you trust me it will save you a lot of time\nand headache in the future. Plus, you'll enjoy free autocompletion provided by\nthe language server."}],"\n",["$","h2",null,{"id":"improved-code-quality-and-maintainability","children":[["$","a","link-improved-code-quality-and-maintainability",{"href":"#improved-code-quality-and-maintainability","className":"anchor"}],"Improved Code Quality and Maintainability"]}],"\n",["$","p",null,{"children":"Static typing contributes to better code quality and maintainability. By\nenforcing a clear and consistent type system, static typing helps us write more\nrobust and reliable code. The type annotations provide valuable documentation,\nmaking it easier for other team members to understand and work with the\ncodebase."}],"\n",["$","h2",null,{"id":"conclusion","children":[["$","a","link-conclusion",{"href":"#conclusion","className":"anchor"}],"Conclusion"]}],"\n",["$","p",null,{"children":"Initially, the setup may look like a lot of work, but once you get used to it,\nit's an investment that will definitely pay off in the long run. You will thank\nyourself in the future for taking the time to get this right. (Not joking - I'm\na victim of this myself.)"}]] a:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"Exploring the power of static typing"}],["$","meta","3",{"name":"description","content":"There's a long debate about static and dynamic typing in the world of software. But, I think static typing is superior."}],["$","meta","4",{"property":"og:title","content":"Exploring the power of static typing"}],["$","meta","5",{"property":"og:description","content":"There's a long debate about static and dynamic typing in the world of software. But, I think static typing is superior."}],["$","meta","6",{"property":"og:url","content":"https://aelpxy.dev/blog/exploring-the-power-of-static-typing"}],["$","meta","7",{"property":"og:type","content":"article"}],["$","meta","8",{"property":"article:published_time","content":"2022-06-07"}],["$","meta","9",{"name":"twitter:card","content":"summary_large_image"}],["$","meta","10",{"name":"twitter:title","content":"Exploring the power of static typing"}],["$","meta","11",{"name":"twitter:description","content":"There's a long debate about static and dynamic typing in the world of software. But, I think static typing is superior."}],["$","meta","12",{"name":"next-size-adjust"}]] 1:null b:["$","div",null,{"className":"my-6","children":["$","div",null,{"className":"rounded-lg border border-stone-700 bg-stone-900","children":["$","div",null,{"className":"overflow-x-auto","children":["$","div",null,{"dangerouslySetInnerHTML":{"__html":"
const user = await getUser(id)\n\nconsole.log(user)
"}}]}]}]}]
d:T1314,type UserType = 'user' | 'admin'
interface User {
name: string
email: string
type: UserType
isActive?: boolean
}
interface Error {
message: string
code: number
}
async function getUser(id: string): Promise<User | Error> {
try {
const { error, userData } = await fetchUser(id)
if (!userData) {
return error
}
return userData as User
} catch (error) {
return {
message: 'internal_server_error',
code: 500,
}
}
}
c:["$","div",null,{"className":"my-6","children":["$","div",null,{"className":"rounded-lg border border-stone-700 bg-stone-900","children":["$","div",null,{"className":"overflow-x-auto","children":["$","div",null,{"dangerouslySetInnerHTML":{"__html":"$d"}}]}]}]}]