<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Taric Ov on Medium]]></title>
        <description><![CDATA[Stories by Taric Ov on Medium]]></description>
        <link>https://medium.com/@taricov?source=rss-35f5c1b349a7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*i6l-XjqhNK6hYB3hVnXNpw.png</url>
            <title>Stories by Taric Ov on Medium</title>
            <link>https://medium.com/@taricov?source=rss-35f5c1b349a7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:27:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taricov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[TypeScript (2): Handling Nullable Types (5 quick ways)]]></title>
            <link>https://taricov.medium.com/typescript-2-handling-nullable-types-5-quick-ways-754b09dd34b6?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/754b09dd34b6</guid>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Sun, 03 Mar 2024 16:44:22 GMT</pubDate>
            <atom:updated>2024-03-03T16:56:38.703Z</atom:updated>
            <content:encoded><![CDATA[<p>Null-able types are all about typing a variable value that can either hold a valid value of a specific type or be NULL or UNDEFINED.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X38xVNsTF1beYPbEyKuhiQ.png" /></figure><p>How to handle them in typescript? so writing robust and error-free TypeScript code.</p><p>1. Declare Null-able Types: [using the union operator (`|`)]:</p><pre>let name: string | null;<br>   let age: number | undefined;</pre><p>2. Checking for Nullable Values: [use type guards]</p><pre>if (name !== null) {<br>       console.log(name.toUpperCase());<br>   }</pre><p>3. Optional typing: [use Optional chaining]:</p><pre>console.log(age?.toFixed(2));</pre><p>4. Assigning Nullable Values: [assigned null or undefined explicitly]:</p><pre>name = null;<br>   age = undefined;</pre><p>5. Nullish Coalescing Operator (`??`):</p><ul><li>It returns the right-hand operand if the left-hand operand is null or undefined.</li></ul><pre>let result: string;<br> let nullableValue: string | null = null;<br><br>// Using nullish coalescing operator<br>   result = nullableValue ?? &quot;Default Value&quot;;<br>   console.log(result); // Output: &quot;Default Value&quot;</pre><p>By understanding how to handle nullable types in TypeScript, you can write more robust and error-resistant code that gracefully handles nullable values.</p><p>Article on Linkedin: <a href="https://www.linkedin.com/posts/taricov_typescript-developercommunity-softwareengineering-activity-7170098531318284288-hoIj?utm_source=share&amp;utm_medium=member_desktop">https://www.linkedin.com/posts/taricov_typescript-developercommunity-softwareengineering-activity-7170098531318284288-hoIj?utm_source=share&amp;utm_medium=member_desktop</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=754b09dd34b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(1) TypeScript: Create Optional Types From Old Types?]]></title>
            <link>https://taricov.medium.com/1-typescript-create-optional-types-from-old-types-2ac5ee2b6106?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ac5ee2b6106</guid>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Sat, 20 Jan 2024 15:57:38 GMT</pubDate>
            <atom:updated>2024-01-20T15:57:38.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caJ_Cyc9benlXM_C8IORnw.png" /></figure><p>Here’s a quick tip on how to use already-existing types to create a new type with optional properties without changing the original type:</p><pre>type ToptionalProps&lt;T&gt; = { [K in keyof T]?: T[K] };<br><br>// Example Interface:<br><br>interface Tuser {<br>  id: number;<br>  name: string;<br>  email: string;<br>}<br><br>type ToptionalUser = ToptionalProps&lt;Tuser&gt;;<br><br>// Equivalent to: type ToptionalUser = { id?: number; name?: string; email?: string };<br><br>// ==== And you can play around and Pick and Omit like so: =====<br><br>type TnameAndIdUser = Omit&lt;Tuser, &quot;email&quot;&gt;<br>type TomittedOptionalProps&lt;T&gt; = { [K in keyof T]?: T[K] };<br><br>type ToptionalUser2 = TomittedOptionalProps&lt;TnameAndIdUser&gt;;<br><br>const newUser: ToptionalUser2 = {email: &quot;sad&quot;}<br>// Error &#39;email&#39; does not exist in type &#39;TpickedOptionalProps&lt;x&gt;&#39;;</pre><p>With this trick, you can now easily create a type where all properties of the original type become optional.</p><p>Ts Playground:</p><p><a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAKg9mYBLOA7AhgGwAoCcEDOAPDAHxQC8UA3lANoDSUSqUA1hCHAGawC6AfgBcsRnygBfANwAoGQHp5UAKIAPdAFswmaAElUwCLm7oAxhCFyWh42egwArgSM0ZUZgBMRqBxoBGRrLuGBoWUATAuCwA5kFQEBroSJgiEVGosTIScqCQsAjIaFgAqs64lPmIKBg4+GDEjmWksgpKygCODkgAblgQBlDAcCK59gXVJWUVtEgewlA+-oELmhDzaTFS8YnJ65Exki2KlBSnUACCqB5QXA5Qpuis2uggUOj4DldvX9hIpmzfa4AeQ0SGAUEwSA44WGJ1OFBy4HsIQglw8ug8pRcVBBYJITiMABooAAiBJJTAk0gyUb5UHAQweIFVIq1QgkchUWiMZisDhcXgwQQiGBiQ6IvLwFk1LG4ABMFXg9MZzMKNTw7JgKLRGNlzTkpjQEQWEAA7rKReNWbKFVzyckRCSCOgPCTssdlLh8OUAOT2zA+qAeOAQAgLODgiCqJDGliDJFQH0wMB-DhM6VYDX1IiqUg+qRAA">TS Playground - An online editor for exploring TypeScript and JavaScript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ac5ee2b6106" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do We Really Hate Bugs? A Call For Peace… ⎯ CringyAI And Moving Things #2]]></title>
            <link>https://taricov.medium.com/do-we-really-hate-bugs-a-call-for-peace-cringyai-and-moving-things-2-1219095138c0?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1219095138c0</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Tue, 20 Jun 2023 13:37:29 GMT</pubDate>
            <atom:updated>2023-06-20T14:52:05.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*57OTE_wzk_HGxywLNsoMdA.png" /><figcaption><strong>CringyAI and Moving Things</strong></figcaption></figure><blockquote>This is the <strong>2nd</strong> <strong>edition</strong> of a <em>light-weight tech-comic newsletter</em> ⎯ <strong>CringyAI and Moving Things</strong> shares thought-provoking ideas about tech and AI .. for more visit: <a href="https://bit.ly/cringyai">https://bit.ly/cringyai</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBdXSfZ0qH7t6C-lO5_GJQ.jpeg" /><figcaption>Do We Really Hate Bugs? A Call For Peace…</figcaption></figure><p>While bugs really move and infect plants, skin, and code .. they have much of a role in our lives that should make us take them seriously, … I mean differently! 😅</p><p>Of all sorts of bugs 🐞 the one in the code could really make you lose a lot of money 🤣 and you can not kill them by using pesticides, but rather by having a peaceful-mind that never runs outta patience, digging deep and reviewing the codebase that you earlier celebrated its release … what the bug!</p><p>With AI, we reached the point where we are, now, developing AI that is capable of killing real bugs:</p><p><em>“AI-controlled robotic laser can target and kill cockroaches” — newscientist.com</em></p><p>If you ask me, I couldn’t let this get past my imagination 👉 This is <strong>StarWars In The Field </strong>lol 😂</p><p>but how about a bug in the AI? <br>could we have a robot w/ laser? but it has a bug in their codebase … re-appearing in the news headlines again but this time it reads:</p><p><em>“Uncontrolled AI robot chasing framers with a green laser beam” — thatisinmymind.me</em></p><p>but wait? what about the poor farmers.. and how could they self-defend themselves against the out-of-control robot?</p><p>for that we should continue with what the news could read:</p><p><em>“…and while farmers are making their way out of the field, they keep releasing more bugs to distract the raged robot.” </em>😂</p><p>That’s a fair fight, bugs vs bugs and we live in the margin.</p><p>But seriously, if we could ever take anything seriously in this publication 😆 .. why we do not enjoy bugs?</p><p>We all know a bug could be the feature u r about to discover, it could be your app’s competitive edge, or it could be your best selling point.</p><p>Is it just because they r not intended? Or just cuz they feel off?</p><ul><li>Cuz I know as everybody knows that not all bugs r hated, like..</li></ul><p>— ..imagine a switch button that toggles on/off but it fills the whole width of your screen so the switcher travels onChange from edge to edge .. wouldn’t that be playful and inviting for more session duration avgs and lesser bounce rates .. pllllllllllz 🙃</p><ul><li>How about a website that is built w/ unintentional components, full of bugs..</li></ul><p>— ..man, I’d stay there, forever, adventuring for 👉 from where the sidebar could show and come in for me 😂😂</p><ul><li>Wait! ✋</li></ul><p>— …how about an app for developers that rewards (The Best Generated Bug) and we r battling 🙃🤣🤣</p><p>That’s enough for today 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1219095138c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How About A Game.. That Plays You? ⎯ CringyAI And Moving Things #1]]></title>
            <link>https://taricov.medium.com/how-about-a-game-that-plays-you-cringyai-and-moving-things-1-90b33d07e903?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/90b33d07e903</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[games]]></category>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 13:57:31 GMT</pubDate>
            <atom:updated>2023-06-16T14:07:12.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*57OTE_wzk_HGxywLNsoMdA.png" /></figure><blockquote>This is the <strong>1st</strong> <strong>edition</strong> of a <em>light-weight tech-comic newsletter</em> ⎯ <strong>CringyAI and Moving Things</strong> shares thought-provoking ideas about tech and AI .. for more visit: <a href="https://bit.ly/cringyai">https://bit.ly/cringyai</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ftAAq-OOJr1h4u7TzskfZw.jpeg" /></figure><p>How about a game where you can free-talk to other NPC (non-player character) and they argue and discuss your choices/decisions in the game 🫤</p><p>So the characters (NPCs) could be for example chatgpt-based trained agents or better? **DRL models** (deep reinforcement learning) 🧐</p><blockquote>That makes it an open-ended game where you could easily get stuck <em>lol 👽</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90b33d07e903" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript: Any…? Does <any> Have Any Benefits in Your Code?]]></title>
            <link>https://medium.com/geekculture/typescript-any-does-any-have-any-benefits-in-your-code-47888cd7ec9c?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/47888cd7ec9c</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Wed, 14 Jun 2023 12:32:20 GMT</pubDate>
            <atom:updated>2023-06-14T12:32:20.271Z</atom:updated>
            <content:encoded><![CDATA[<h3>The &lt;any&gt; type in TypeScript is a dangerous &quot;escape hatch&quot; from the type system.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-68hvVXu153IwovR93rwdA.png" /></figure><p>We all know that Typescript is a powerful tool for:</p><ul><li>type safety, and</li><li>catching errors early in the development process.</li></ul><p>However, there is one type that can be detrimental to your codebase if used carelessly — the infamous `any` type.</p><h3>“Any..?” vs “I like to be specific about things!”</h3><p>Imagine that you are at the grocery and you go over the cheese section:</p><p>_ “do you have cheese today guyz??”<br>= “definitely!!” — says the seller<br>_ “gimme some”<br>= “of what?”<br>_ “any..!”</p><p>and you repeat that in the fruits, meats, beauty… etc sections .. what you will end up with?</p><blockquote><strong>Things you have never desired and you may have paid (incurred) high cost for them.</strong></blockquote><p>let’s see some of both <strong>UNdesired</strong> results and how high it could cost you using &lt;any&gt; in your codebase.</p><h3>The Pitfalls of Using the `any` Type:</h3><p>Using `any` may seem tempting at times, but it comes at a cost. Here are some reasons why you should think twice before reaching for the `any` type:</p><p>1. <strong>Type Safety Leakage</strong>:</p><p>Accessing members on an `any`-typed value bypasses TypeScript’s type checking, creating a potential source of bugs and reducing the benefits of static typing.</p><pre>let data: any = 42;<br> data.foo(); // No type checking, potential runtime error</pre><p>2. <strong>Loss of IntelliSense</strong>:</p><p>When using `any`, you lose the benefits of TypeScript’s powerful IntelliSense, making code exploration and auto-completion less effective.</p><pre>let user: any = getUser();<br> user. // No IntelliSense, decreased productivity</pre><p>3. <strong>Lack of Documentation</strong>:</p><p>`any` type erases valuable information about the expected data shape, making it harder for other developers (including your future self) to understand and maintain the code.</p><pre>function processResponse(data: any) {<br> // Missing documentation about the expected structure of the data<br> // Other developers need to rely on external documentation or guesswork<br> }</pre><p>4. <strong>Compiler Warnings and Errors</strong>:<br>- The use of `any` suppresses valuable compiler warnings and errors that can help catch potential issues before <em>they become runtime bugs</em>.</p><pre>let x: any = 42;<br> x.foo(); // No compile-time warning, potential runtime error</pre><h3>Any Alternatives…? I mean Any Alternative to &lt;any&gt;?</h3><p>Instead of resorting to the `any` type, consider these alternatives to ensure type safety and maintainable code:</p><p>1.<strong> Define Specific Types</strong>:</p><p>Create your types 😑 types that you know and want to retrieve .. Use interfaces or types that accurately represent the shape of your data, providing clarity and enhancing the understanding of your codebase, for example:</p><pre>interface User {<br> id: number;<br> name: string;<br> email: string;<br> }</pre><p>2. <strong>Use Union Types</strong>:</p><p>Nothing feels warmer than a Union 😄 even if it’s other ppl’s uions .. so why stay in the cold? lol<br>You really could combine multiple types using union types (`|`) to express the flexibility of a variable without sacrificing type safety:</p><pre>let result: User | null = getUserById(id); //null btw never felt warm to meeeee 😀<br> if (result !== null) {<br> // Type inference works, preserving type safety<br> console.log(result.name);<br> }</pre><p>3. <strong>Leverage Generics</strong>: 💪</p><p>We have been talking about Generics for a while now and how magical they are to give your code flexibility. (to even split 😜)</p><p>Use generics to create reusable components that work with different data types while maintaining type safety…</p><pre>function fetchAndProcessData&lt;T&gt;(url: string): T {<br> // Type inference works, preserving type safety<br> const data = fetchData(url);<br> return processData&lt;T&gt;(data);<br> }</pre><blockquote>- For maintainability … use more specific types, union types, and generics.<br>- For bugs … use &lt;any&gt;</blockquote><p>…for me, I know bugs as interesting creatures or JIRA issues 😆</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47888cd7ec9c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/typescript-any-does-any-have-any-benefits-in-your-code-47888cd7ec9c">TypeScript: Any…? Does &lt;any&gt; Have Any Benefits in Your Code?</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Typescript: Typing Your API Requests — Generics Hacks #4]]></title>
            <link>https://medium.com/geekculture/typescript-typing-your-api-requests-generics-hacks-4-540644951f9b?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/540644951f9b</guid>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Wed, 14 Jun 2023 07:14:54 GMT</pubDate>
            <atom:updated>2023-06-14T07:14:54.217Z</atom:updated>
            <content:encoded><![CDATA[<h3>Typescript: Typing Your API Requests — Generics Hacks #4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hJpUtmSozBj1A2qu0P0yaw.png" /><figcaption>Typing a REST API Request</figcaption></figure><p>Are you ready to take your REST API requests to the next level? Buckle up, because… Ah! 😑 why go boring? while i can call u guyzzzzz 🤣</p><p>Btw, do you know? Along this short series, TypeScript and typing cases had come to a closer place to us, and are about to become that handy that do a lot of magic by a few tricks! 🙂</p><p>This is not generics-related tut but it’s extending on the last Generics Hacks article.. we will use TypeScript generics to provide a type-safe response coming from REST API requests whatever they were.</p><h3>TypeScript’s UNKNOWN = The New Way of Knowing Things.</h3><p>We’ll be using <em>`fetch` API</em> in this example, and will be using<strong> dummyjson.com to </strong>fetch dummy data for demonstration:</p><blockquote>Notes will precede code blocks … you can check out the code first and then read the notes.</blockquote><ol><li>Setting some variables for making API requests.</li></ol><pre>// STEP 1<br>// setting variables<br>const url:string = &quot;https://dummyjson.com&quot;;<br>const endPoint: string = &quot;/users&quot;<br>// u could use /posts or /products for other data types</pre><p>2. This is the function where we request data…</p><ul><li>Promise&lt;unknown&gt; leverage the use of one of the primitive types in Typescript unknown</li><li>unknown is way safer than any that mist typing and make</li><li>unknown is so useful for APIs when you need to perform type checking before you use them.</li><li>In contrast to any which means <strong><em>disable type checking </em></strong>unknown is a Typescript real and capable type, it’s just the least effective among the more-specific others.</li><li>The real power of unknown typing value is that you can use type guards to narrow the type and get more accurate type-checking on narrowed types.</li></ul><pre>// STEP 2<br>async function GetAllItems(<br>  url: string, endpoint: string<br>): Promise&lt;unknown&gt; {<br>  const response = await fetch(url + endpoint);<br>  const json = await response.json();<br>  return json.users <br>}</pre><p>3. 🔥 <strong>A</strong> <strong>TRICK 🔥</strong>: now we declare an example user object w/ some/all properties. We will use that obj. to prototype that as our new base type User for that API call result</p><pre>// STEP 3<br>const userExample = {<br>  id: &#39;&#39;,<br>  firstName: &#39;&#39;,<br>  lastName: &#39;&#39;,<br>}<br>type User = typeof userExample</pre><p>4. Here we goooo.. one more step before sending our request:</p><ul><li>We are making a type-checker function based on the base-type User</li><li>The checker will take a user as a param to check on its type</li><li>And will return the result narrowed using the Type-gaurd operator is</li><li>So if user passes the checker and evaluates to =&gt; true</li><li>That will enforce our typing for intellisense and type-safe use for all users</li></ul><pre>// STEP 4<br>function isUser(user: any): user is User {<br>  // defaulting to false for effective checking<br>  let checking = false<br>  // iterating over keys from the `userExample` as they r the same keys for `User`<br>  for(const t of Object.keys(userExample)){<br>   checking = t in user<br>    if(!checking)<br>      return false<br>  }<br>  // if only one key evaluetes false 👆 user fails the test<br>  // otherwise it passes and return true 👇 and pass the success status to all the array result of users<br>  return checking<br>}</pre><p>5. Now we call our API endpoint and return:</p><pre>// STEP 5<br>SendReq()<br>async function SendReq(<br>): Promise&lt;User | null&gt; {<br>  const allUsers:any = await GetAllItems(url, endPoint) // allUsers as `any` here to bypass the linter and we r about to check the type ourselves<br>  const user = allUsers[0] <br>  if (user &amp;&amp; isUser(user)) {<br>    console.log(user)<br>    // now user is typed and can be used safely <br>    return allUsers; <br>  }<br>  return null; // in case isUser(user) checking fails<br>}</pre><p><strong>➕…and intellisense is working 🟢</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3tP1OO3hRyH6EEYdj0lN9w.png" /></figure><p>🟢🟢 Check out the full example code in the Typescript playground (try it urself)</p><p><a href="https://www.typescriptlang.org/play?#code/PTAEGUBUFEAVQIwCgSgM4FMAuWCWA7Ac1ADcBDAJ1zICMAbDNJAYwHt80tQBXCugLk5UioALygARAAscABzT8QAE24BbVQE8AVmnYA6NqokBuFu06gM+JbFYEs-dFmHFxE4N0wU0ElGG6gbNx0SjyYoMCyrJxooKwUEbIUrCrMWLEAZvFxWFIYCUpkWGSgWBqyjEhVqFBwoABMSGRoGvjMoBncbXjsoADi2ACCdHQAklgYqmgAFEigPHyOQgSEADSW1lH2S84rSACUjrDJqriYADxdANb4rADu+AB8oADec4HmXBSMURwYYqAyHcyLguBlsMwpNNeHRQABqDZKLb4LD7UzzNgcLg6XriIEgr4-cwYPQ4-DTNHvb5YXj4UBkvSefKxJAAXyqfggMHgAGYzFiwvloAAPMiqWQMAFvea4JSOADk8tW7wyuG8WAAcmKMAqle86M1Ndrdcr2WUKqAAKpeAHmjCsDKCigisUSjAczm1eAAFk5uX+kIwzCu+VAd1wI1KZBDgKdgNiZDpskoYtKrECeWDcTpoNids5idC4cj1NppTyoG+aGCXHwlGSdwwoU8K3L-0g5QwAFpCGReKFWBUKEVsgADM6jzm6UC4R1MhLJtCYPMVwPB0OFyzkOjcIqMNNiZ7Obju1C5IphiOwqxZCjMf6sXilcqt28zlEYEZnKzhTd2rtoGQ4KCh02RkJG85MJ03S4L0ZzWvk0JeI4iYaIccZnFaNrShEYBKBgGR9nQeAiFg6aEXQ4RvgR4JpLgJABpmVx7PMDBcGuzEiOIFGYO8qCgvkRStqwDEJCGGiZCcbagKO84uuKDCjvGbYaJW0mAao-ziZkY4IRQk7zLe0yYhYXAOqAADyNBaEGWB6NpSFCqKCkYPs+w4RmQaca4pTvk67wyhk0wAIQcSs+wBfMlbYGWPHuvM7LzPxjrsHQqnsFpGCqRg24nhMmTgeEgC8G4AYjtxoREYrv8+VYHxYCsP6FDhuEoKgIuy6AtY0U0hQdLHv8RWAOI7nWhO16ncMw95Lk4RSeAe4Gwv6gIUMOqlVjWcRzl4TDzKWvWecGezsp63KgAArEg4BWEoABKGAAI4Uk0LRtB0XR0b0V3WHdj0HEcJzfucemgAAPqA+DBHQzxvKgtx3GGAYLXET6DLAoyIsiXCbnt+D8JywN2tm6BBlNTCw5Dz4Wr0FV0O8JlYyMekKKhAL4q1AxYMMYwTFM0J8Os122PY+y4YCjPbcpo6oUpeTfAeNDlM0VWgHQ9gbl1jZqbQj5cGRB1XNJhOPt4n4MTtHwCvOrPi8yADaAAMAC6oDvLOoCOQkABknszmgeke25ryRSZrAMHodCsIQAeRbD9wYXmnahJuzCJqAND-EyoSAeCaUu1F3VlgtTPGHnoCJQX+0QyMJf8XSKctX7XgB-rr4gpRbJAA">TS Playground - An online editor for exploring TypeScript and JavaScript</a></p><p>🟢🟢 Check out the full example code gist:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c909daaec1637a1c3954e9b156cadec/href">https://medium.com/media/8c909daaec1637a1c3954e9b156cadec/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=540644951f9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/typescript-typing-your-api-requests-generics-hacks-4-540644951f9b">Typescript: Typing Your API Requests — Generics Hacks #4</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Typescript: How to use Generics to make your own Type Templates?]]></title>
            <link>https://taricov.medium.com/typescript-how-to-use-generics-to-make-your-own-type-templates-e2f4b151381f?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2f4b151381f</guid>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 07:06:34 GMT</pubDate>
            <atom:updated>2023-06-01T07:06:34.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Extending from the last post about Type Utilities…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owtlS82RG-F7yY2CglqheA.png" /></figure><p>After we talked about types utilities the last post, let’s extend and see more advanced usage of generics in typescript and we could build our own type templates that can be reused across your projects:</p><p>let’s say that we will type a social tweet/post data…</p><pre>interface postProps {<br>  name: string;<br>  relativeTime: string;<br>  tweet: string;<br>  retweets: number;<br>  likes: number;<br>  comments: number;<br>  userImg: string;<br>  liked: () =&gt; void;<br>  likedUsers: Array&lt;{ name: string; img_src: string; id: number }&gt;;<br>}</pre><p>we are familiar now w/ interfaces in typescript and to put it in simple quick words, interfaces are type contracts that an entity/object should conform to.</p><p>Now..</p><pre>type readOnlyProps&lt;T&gt; = {<br>  readonly [P in keyof T]: T[P];<br>};</pre><p>Here we go.. This is a type template of areadonly that converts any type props into readonly mode using the keyword readonly :</p><ol><li>We use&lt;T&gt; as our parameter of props.</li><li>And then we use this syntax [P in keyof T] to loop through props keys and re-print them w/ the prepended keyword readonly</li><li>T[P] is so obviously brings in the value of the key for each prop</li><li>Now we can use this template, like this:</li></ol><pre>type readOnlyPostPorps = readOnlyProps&lt;postProps&gt;;<br>//readOnlyPostPorps is our new type<br>//readOnlyProps is our type template/converter we defined b4<br>//postProps us our original interface</pre><p>As you see how generics:</p><ol><li>makes things handy</li><li>generates from already existing types,</li><li>prevents us from repeating/re-typing props (reusability)</li><li>opens possibilities for more complex flows</li></ol><p>Now..</p><p>Try out the example and play around w/ the template and see what you can come up w/ new:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftypescript-typing-hacks-w-generics-l6u9o6%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fkztteb&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fl6u9o6%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/796c1fbe8aa1e1122aa0962fa631d47e/href">https://medium.com/media/796c1fbe8aa1e1122aa0962fa631d47e/href</a></iframe><p>till next time.. keep ur type tight.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2f4b151381f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Typescript: Type Utilities for the goodness and reusability]]></title>
            <link>https://medium.com/geekculture/typescript-type-utilities-for-the-goodness-and-reusability-d661bb261dd7?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d661bb261dd7</guid>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Mon, 29 May 2023 07:01:52 GMT</pubDate>
            <atom:updated>2023-05-29T07:01:52.563Z</atom:updated>
            <content:encoded><![CDATA[<p>How to use Pick/Omit/Exclude/etc.. to do cool stuff..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHwTOB0X9mom7uiIQhKqgA.png" /></figure><p>The pick is a utility .. utility type that allows you to select specific properties from an object type and create a new type with only those properties .. cool?</p><pre>// Define a User interface<br>interface User {<br>  name: string;<br>  age: number;<br>  address: string;<br>  email: string;<br>  single: boolean;<br>  job: string;<br>  degree: string;<br>}<br><br>// Now we r sliccccing 😀<br>type UserBasicInfo = Pick&lt;User, &#39;name&#39; | &#39;age&#39;&gt;;<br><br>const newUser: UserBasicInfo = {<br>  name: &#39;Taric Ov&#39;,<br>  age: 28<br>};<br><br>console.log(newUser); // { name: &#39;Taric Ov&#39;, age: 28 }</pre><p>In the above example:</p><ol><li>We have an interface Userthat defines their properties.</li><li>We used the Pick&lt;User, &#39;name&#39; | &#39;age&#39;&gt; type to create a new type called PersonBasicInfo that only includes the name and age properties from the whole User interface.</li><li>We then created an object of the type UserBasicInfo called newUser with the selected properties.</li></ol><p>got it? if yes? that sounds great cuz u know what? you now got Omit/Exclude as well 😮💪 congrats 😉</p><p>if still need more explanation? try it in code and follow the comments 😊</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftypescript-type-utilities-b03y4r%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fb03y4r&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fb03y4r%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/1931eff2eb34a901706c10cbabf2b977/href">https://medium.com/media/1931eff2eb34a901706c10cbabf2b977/href</a></iframe><p>So..</p><p>Omit is also a utility type that does the opposite of Pick. It allows you to exclude specific properties from an object type and create a new type without those properties.</p><p>— The terms “omit” and “exclude” can be used interchangeably in the context of utility types in TypeScript. Both `Omit` and `Exclude` are utility types that provide similar functionality but with slight differences.</p><pre><br>// Omitting <br>interface User {<br>  name: string;<br>  age: number;<br>  address: string;<br>}<br>type UserWithoutAddress = Omit&lt;User, &#39;address&#39;&gt;;<br><br>//Excluding numbers from a literal<br>type Numbers = 1 | 2 | 3 | 4 | 5;<br>type ExcludedNumbers = Exclude&lt;Numbers, 1 | 3 | 5&gt;;<br>// ExcludedNumbers: 2 | 4</pre><h4>What About the other utility types in TypeScript?</h4><p>1. Partial&lt;T&gt;: This utility type creates a new type that makes all properties of the original type `T` 👉 <strong>optional.</strong></p><p>2. Required&lt;T&gt;: This utility type creates a new type that makes all properties of the original type `T` 👉 <strong>required</strong>.</p><p>3. Readonly&lt;T&gt;: This utility type creates a new type that makes all properties of the original type `T` 👉 <strong>read-only.</strong></p><p>4. Record&lt;T,K&gt;: This utility type creates a new type with keys of type `K` and values of type `T` 👉 <strong>It’s often used to define dictionaries or mappings.</strong></p><p>These utility types, along with `Omit` and `Exclude`, provide powerful ways to manipulate and transform types and even to do cool tricks in TypeScript.. and that’s what we are to explore in the next tutorial.</p><p>till then.. keep ur types tight 💪</p><p>Next: Type Templates 🤘(…out the oven)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d661bb261dd7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/typescript-type-utilities-for-the-goodness-and-reusability-d661bb261dd7">Typescript: Type Utilities for the goodness and reusability</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generics Hacks (1): ReadOnly in Typescript w/ 3 Examples]]></title>
            <link>https://medium.com/geekculture/generics-hacks-1-readonly-in-typescript-w-3-examples-7658d12ab1be?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7658d12ab1be</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[typescript-with-react]]></category>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Sat, 20 May 2023 16:24:11 GMT</pubDate>
            <atom:updated>2023-05-20T16:24:11.862Z</atom:updated>
            <content:encoded><![CDATA[<h3>Generics Hacks #: is a quick tip at a time about using typescript generics.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QQivn1mE0eKGtoJ0TWfTNw.png" /></figure><p>`readonly` is a keyword in TypeScript that we use when we want to make a property UNchangeable, so the value of the property cannot be changed after it has been set.</p><h4>1) How to use the `readonly` keyword on a property of a type?</h4><pre>type Person = {<br>  readonly name: string;<br>  age: number<br>  }<br>  <br>   const person1: Person = {<br>      name = &quot;John&quot;;<br>      age: 30<br>  }<br>  // name property will not change &#39;cuz it was assigned to be readonly<br>  person1.name = &quot;Sarah&quot;; ❌<br>  person1.age = 20; ✅</pre><h4>2) How to use the `readonly` keyword on an interface?</h4><pre>interface Car <br>  make: string;<br>  model: string;<br>}<br><br>const readonlyCar1: Readonly&lt;Car&gt; = {<br>  make: &quot;Tesla&quot;,<br>  model: &quot;Model S&quot;<br>};<br><br>// This will not compile because the make property is readonly<br>readonlyCar1.make = &quot;Toyota&quot;; ❌<br>// This will not compile because the model property is readonly<br>readonlyCar1.model = &quot;Camry&quot;; ❌<br>🟢<br>const car2: Car = {<br>  make: &quot;Tesla&quot;,<br>  model: &quot;Model S&quot;<br>};<br><br>car2.make = &quot;Toyota&quot;; // OK ✅<br>car2.model = &quot;Camry&quot;; // OK ✅</pre><h4>3) How to leverage generics and use the `readonly` keyword dynamically?</h4><p>This is a normal static interface 👇</p><pre>interface postProps {<br>  name: string;<br>  relativeTime: string;<br>  tweet: string;<br>  retweets: number;<br>  likes: number;<br>  comments: number;<br>  userImg: string;<br>  likedUsers: Array&lt;{ name: string; img_src: string; id: number }&gt;;<br>}</pre><p>Let’s say now that we need to have a read-only version of this interface, now we have two scenarios:</p><ol><li>You already know the type: then you could do it manually 🤚 one by one putting thereadonlykeyword before each property.</li><li>You don’t know the type or you know it and it has tons of properties: then <strong>you use generics: </strong>🤓</li></ol><pre>type readOnlyProps&lt;T&gt; = <br>  readonly [K in keyof T]: T[K]; <br>};</pre><p>What that means:</p><ul><li>T is representing avariable for the type that you will use</li><li>K is representing the key of each property in theT type</li><li>you can think of it as an iterator that iterates over the passed types (postProps in this case)</li><li>e.g. first iteration:<br>Input 👉 readonly [name]: postProps[name] <br>output 👉 readonly name: string;</li></ul><p>Now you can create your new type and use it:</p><pre>// your new type:<br>type readOnlyPostPorps = readOnlyProps&lt;postProps&gt;;<br><br>// you could use the new type now:<br>function Post(props: readOnlyPostPorps): JSX.Element {<br>  return (<br>    &lt;&gt;<br>      {...your JSX goes here}<br>    &lt;/&gt;<br>  );<br>}<br>export default Post;</pre><p>Try this live example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Flingering-shadow-pm0d4m%3Ffile%3D%2Fsrc%2Fcomponents%2Fpost.tsx&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fpm0d4m&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fpm0d4m%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/dab9a3fd0a41ab111074e92c7709684d/href">https://medium.com/media/dab9a3fd0a41ab111074e92c7709684d/href</a></iframe><p>Any good in using Read-Only? looks like it does only one thing.</p><ul><li>Prevent bugs 🐞 by preventing developers from accidentally changing the value of a property.</li><li>Improved maintainability 🔧 Code will become easier to maintain thanks to the first point (preventing bugs)</li><li>Improved readability 👊 Code will become easier to read and understand by clearing out what can be changed and what cannot.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7658d12ab1be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/generics-hacks-1-readonly-in-typescript-w-3-examples-7658d12ab1be">Generics Hacks (1): ReadOnly in Typescript w/ 3 Examples</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript Generics… How about pizza?]]></title>
            <link>https://medium.com/geekculture/typescript-generics-how-about-pizza-ab30b37d45a1?source=rss-35f5c1b349a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab30b37d45a1</guid>
            <category><![CDATA[type-safe]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[generics]]></category>
            <dc:creator><![CDATA[Taric Ov]]></dc:creator>
            <pubDate>Sun, 14 May 2023 15:22:02 GMT</pubDate>
            <atom:updated>2023-05-14T19:52:16.218Z</atom:updated>
            <content:encoded><![CDATA[<h3>TypeScript: Generics… How about a pizza?</h3><p>You love pizza, you eat pizza, you order pizza but they deliver “Generics”… you ordered sometin’?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ugB29v9S01y8dsGo-d5Vbw.png" /><figcaption>Typescript Generics vs Pizza</figcaption></figure><h3>Why you might choose to use TypeScript?</h3><p>There are too many perks and benefits you can get from integrating typescript into your projects, but there are 2 reasons in specific that really concern and affect the whole development process and leverage the developer experience:</p><ol><li><strong>Code Reliability:</strong> ⚓️<br><em>TypeScript is a statically typed language that can help catch errors and bugs </em><strong><em>at compile time</em></strong><em> before your code is even run. This can lead to more reliable and predictable code, especially in larger projects.</em></li><li><strong>Code Maintainability:</strong> 🔧<br>TypeScript’s type annotations can make your code easier to understand and navigate, especially for developers who are new to a codebase. Additionally, TypeScript’s features like interfaces and type aliases can help you create reusable, composable code.</li></ol><p>Put that in mind as you go in your Typescript journey and you will appreciate it. By the way, I will not talk much about any typing concepts in this article except Generics cuz i stumbled upon its (What is that???) and really want to demystify it so you can understand it better after i struggled a while.</p><h3>What are generics?</h3><h4>Let’s first bring Pizza! 🍕</h4><p>So imagine we got a pizza, a full-rounded pizza, and you told the pizzeria “Don’t cut it into pieces, i need it as a whole” Now you take it home, and in your kitchen, you got geometric shapes of cutters, e.g. triangles/rectangles/circles/stars/squares; all of these cutters you use to cut your pizzas to have fun sharing star-shaped pizzas w/ your pals.</p><p>But today, you have a big party and you may want to cut the pizza in a more formal yet free way so that you could cut smaller slices— or even cut each slice in a half and each half in a half Lol — so all can eat and enjoy .. NOW you know that you will have to bring a knife this time instead of those pre-defined specific shapes.</p><p>And here&#39;s the bottom line: Generics is the knife that you use to custom-cut pizzas .. that’s it.</p><p>It’s a tool you would use whenever you are uncertain about what types(shapes) you will use in a function(pizza)</p><h4>After eating your pizza: How do generics work? 🤔</h4><p>Generics use a special <strong><em>type variable</em></strong> called T and there are 2 points:</p><ol><li>It’s variable .. you know variables very well like const oneVariableor var anotherVariable;</li><li>but the only difference, it’s a type variable, which means it’s only and all like if you do this: let variable2 = typeof &quot;some string&quot;</li><li>The T here is just a convention, you could call it K it doesn’t matter.</li><li>Now, this T is a type variable and it’s generic, and Oxford Dictionary says:<br><em>| Generic:</em> means general, not specified .. got it?! (yes oxford said that)</li><li>A generic type variable is like a parameter in functional programming that you could replace with arguments like so:</li></ol><pre>function add(x, y){ //x and y are parameters to place-hold for arguments<br>return x + y<br>}<br><br>add(3,4) //3 and 4 are arguments to test the function</pre><p><strong>Code Example:</strong></p><p>Let’s say you want to write ONE function that adds any 2 things together and <strong>still keep your code type-safe</strong> .. hmm</p><blockquote>Remember ✋ we are talking all about types.</blockquote><p>Before I learn Generics, I’d do this I would you could write a function for each type like this:</p><pre>function addStr(a: string, b: string): string {<br>  return a + b;<br>}<br>function addNum(a: number, b: number): number {<br>  return a + b;<br>}<br><br>// Calling the functions 👇👇👇👇👇<br><br>addStr(1, 2); // 3<br>addNum(&quot;a&quot;, &quot;b&quot;); // &quot;ab&quot;</pre><p>But now and while I’ve been learning how to use a knife, I’d write it like that:</p><pre>function add&lt;T&gt;(a: T, b: T): T {<br>  return &lt;any&gt;a + &lt;any&gt;b; <br>//Type &lt;any&gt; here is just for escaping typescript infering unknown-ability<br>}</pre><p>This function now can add any 2 things together, as long as both are the same type. For example, you could call it like this:</p><pre>add(1, 2); // 3<br>add(&quot;a&quot;, &quot;b&quot;); // &quot;ab&quot;<br>add({name: &quot;John&quot;}, {age: 10}); // {name: &quot;John&quot;, age: 10}</pre><p>and if you imagined that you could do this add(2, &quot;4&quot;) .. now you are getting that error:</p><blockquote>ERROR: Argument of type ‘4’ is not assignable to parameter of type ‘2’</blockquote><p>Meaning that your types are safe even when you are not sure of the inputs and their type.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftypescript-generics-basics-kn61u8%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftypescript-generics-basics-kn61u8%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fkn61u8%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/c78c4171505a252dcccd5cfbb5cda1f6/href">https://medium.com/media/c78c4171505a252dcccd5cfbb5cda1f6/href</a></iframe><h3>So Why generics? I thought you know by now!</h3><p>You know by now why, right? but let’s list the benefits:</p><ol><li>Generics allow you to write code that is more 🔄 <strong>reusable</strong>,</li><li>Generics allow you to write code that is more ✅ <strong>type-safe</strong>,</li><li>The compiler checks for the types of arguments you pass to the function and make sure they are <strong>compatible, </strong>avoiding errors in ⚡️ <strong>Compile time </strong>and even before running your app ⚡️</li><li>The compiler infers the type of T and this enables auto-completion to suggest only the available right options ✋<br><em>example: When you call the </em><em>add function, as previously shown, with two numbers, the compiler will infer that the type of </em><em>T is </em><em>number, thus the auto-completer will complain when you use any other types other than numbers. MAGIC ha!</em></li></ol><p>That’s it for today, till next time.. see ya 👊😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab30b37d45a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/typescript-generics-how-about-pizza-ab30b37d45a1">TypeScript Generics… How about pizza?</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>