<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: youxufkhan</title>
    <description>The latest articles on DEV Community by youxufkhan (@youxufkhan).</description>
    <link>https://dev.to/youxufkhan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1462371%2Fadefdda4-a468-4875-acb7-fc156c6874a3.jpeg</url>
      <title>DEV Community: youxufkhan</title>
      <link>https://dev.to/youxufkhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/youxufkhan"/>
    <language>en</language>
    <item>
      <title>Free AI Coding CLI Tools in 2026: A Practical Guide</title>
      <dc:creator>youxufkhan</dc:creator>
      <pubDate>Sat, 18 Apr 2026 15:56:52 +0000</pubDate>
      <link>https://dev.to/youxufkhan/free-ai-coding-cli-tools-in-2026-a-practical-guide-48ig</link>
      <guid>https://dev.to/youxufkhan/free-ai-coding-cli-tools-in-2026-a-practical-guide-48ig</guid>
      <description>&lt;p&gt;AI coding assistants have become essential in modern development workflows. But with the big players pivoting to paid models, finding a free or affordable option is getting harder. Here's what actually works and how to set it up in minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with Major AI Coding Tools
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://claude.com/code" rel="noopener noreferrer"&gt;Claude Code&lt;/a&gt;&lt;/strong&gt; remains the gold standard for CLI-based AI coding. It's powerful, well-integrated, and handles complex codebases beautifully. But the pay-as-you-go pricing adds up fast. If you're using it heavily throughout the day, the costs can surprise you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://gemini.google.com" rel="noopener noreferrer"&gt;Google Gemini&lt;/a&gt;&lt;/strong&gt; initially offered a generous free tier with their top models (Gemini 2.5 and 2.5 Pro). But recent quota changes have made free access significantly more restrictive. The writing is on the wall free tiers rarely survive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://qwen.ai" rel="noopener noreferrer"&gt;Qwen&lt;/a&gt;&lt;/strong&gt; (Alibaba's Qwen 2.5 Coder) offered a compelling free alternative through their CLI, but they ended their free tier just last week. If you were counting on it, too bad.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://openai.com/codex" rel="noopener noreferrer"&gt;OpenAI's Codex&lt;/a&gt;&lt;/strong&gt; is currently free but as the saying goes, "free until it isn't." The tier exists, but how long it lasts is anyone's guess.&lt;/p&gt;




&lt;h2&gt;
  
  
  Free and Open Source Alternatives That Actually Work
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Opencode CLI
&lt;/h3&gt;

&lt;p&gt;My personal favorite. Opencode offers &lt;strong&gt;free models through Opencode Zen&lt;/strong&gt; with surprisingly generous limits. The tool itself is open-source and you can use it for free, or upgrade to paid plans ($5-20/month) for higher limits and more models.&lt;/p&gt;

&lt;p&gt;What sets Opencode apart:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built-in skills system for specialized tasks&lt;/li&gt;
&lt;li&gt;Active plugin ecosystem&lt;/li&gt;
&lt;li&gt;Great documentation&lt;/li&gt;
&lt;li&gt;Runs locally with your choice of models&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Kilo CLI
&lt;/h3&gt;

&lt;p&gt;Another solid open-source option. Kilo routes through their gateway and includes built-in agents: Plan, Build, Debug, and Orchestrator. They offer decent free models without requiring a paid subscription.&lt;/p&gt;




&lt;h2&gt;
  
  
  Supercharge Opencode with Plugins
&lt;/h2&gt;

&lt;p&gt;One of Opencode's strengths is its plugin ecosystem. Here are three plugins worth adding:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/code-yeongyu/oh-my-openagent" rel="noopener noreferrer"&gt;oh-my-openagent&lt;/a&gt; (52.5k ⭐)
&lt;/h3&gt;

&lt;p&gt;Previously called "oh-my-opencode", this is a beast. It gives you a full AI dev team:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sisyphus&lt;/strong&gt; - Main orchestrator that plans, delegates to specialists, and drives tasks to completion&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hephaestus&lt;/strong&gt; - Autonomous deep worker for end-to-end execution&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prometheus&lt;/strong&gt; - Strategic planner that interviews you before touching code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ultrawork&lt;/code&gt; command - one word, all agents activate and don't stop until done&lt;/li&gt;
&lt;li&gt;Hash-anchored edits - prevents stale-line errors&lt;/li&gt;
&lt;li&gt;Built-in MCPs (web search, official docs, GitHub search)&lt;/li&gt;
&lt;li&gt;Ralph Loop - self-referential loop that keeps working until 100% done&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/obra/superpowers" rel="noopener noreferrer"&gt;Superpowers&lt;/a&gt; (159k ⭐)
&lt;/h3&gt;

&lt;p&gt;A complete software development methodology. The workflow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;brainstorming&lt;/strong&gt; - Refines your idea before writing code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;using-git-worktrees&lt;/strong&gt; - Creates isolated workspace on new branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;writing-plans&lt;/strong&gt; - Breaks work into 2-5 minute tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;subagent-driven-development&lt;/strong&gt; - Dispatches agents per task with two-stage review&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;test-driven-development&lt;/strong&gt; - Enforces RED-GREEN-REFACTOR&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;requesting-code-review&lt;/strong&gt; - Reviews before continuing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;finishing-a-development-branch&lt;/strong&gt; - Verifies tests, presents merge options&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Skills include systematic-debugging, verification-before-completion, and writing-skills.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/msitarzewski/agency-agents" rel="noopener noreferrer"&gt;Agency&lt;/a&gt; (82k ⭐)
&lt;/h3&gt;

&lt;p&gt;50+ specialized agents across different divisions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engineering&lt;/strong&gt;: Frontend Developer, Backend Architect, AI Engineer, DevOps, Security Engineer, SRE, Database Optimizer, Technical Writer&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design&lt;/strong&gt;: UI Designer, UX Researcher, Brand Guardian, Whimsy Injector, Visual Storyteller&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marketing&lt;/strong&gt;: Growth Hacker, Content Creator, SEO Specialist, Twitter Engager, TikTok Strategist&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sales&lt;/strong&gt;: Outbound Strategist, Deal Strategist, Sales Engineer, Pipeline Analyst&lt;/p&gt;

&lt;p&gt;Each agent has personality, processes, and measurable deliverables.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Solution: One-Command Setup
&lt;/h2&gt;

&lt;p&gt;I got tired of manually configuring Opencode with the plugins and free models I wanted. So I built &lt;strong&gt;my-opencode-config&lt;/strong&gt; a tool that sets up everything in one command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installs Opencode with OhMyOpenagent&lt;/li&gt;
&lt;li&gt;Pre-configures Superpowers and Agency agents&lt;/li&gt;
&lt;li&gt;Sets up Gemini free models via OAuth&lt;/li&gt;
&lt;li&gt;Configures Opencode Zen free models&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx my-opencode-config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or check out the &lt;a href="https://github.com/youxufkhan/my-opencode-config" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; for more options.&lt;/p&gt;

&lt;p&gt;That's it. One command and you have a fully configured AI coding CLI with free models and premium plugins.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Use Daily
&lt;/h2&gt;

&lt;p&gt;For my daily coding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Opencode&lt;/strong&gt; as my primary CLI (configured via my-opencode-config)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kilo&lt;/strong&gt; as backup when I need different model quirks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Claude Code&lt;/strong&gt; for specific tasks where it shines&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;The landscape shifts fast. Free tiers come and go. But the tools above work today and my setup script gives you a running start without the configuration headaches.&lt;/p&gt;

&lt;p&gt;What are you using for AI-assisted coding? Drop your favorites in the comments.&lt;/p&gt;




</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>coding</category>
    </item>
    <item>
      <title>Getting Started with TypeScript: Type Annotations &amp; Type Inference (Part I)</title>
      <dc:creator>youxufkhan</dc:creator>
      <pubDate>Mon, 08 Jul 2024 15:43:10 +0000</pubDate>
      <link>https://dev.to/youxufkhan/getting-started-with-typescript-type-annotations-type-inference-part-i-2mgg</link>
      <guid>https://dev.to/youxufkhan/getting-started-with-typescript-type-annotations-type-inference-part-i-2mgg</guid>
      <description>&lt;p&gt;Type annotations and type inference are two different systems in typescript but in this post we will talk about them in parallel. &lt;/p&gt;

&lt;h2&gt;
  
  
  Type Annotations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Code we add to tell TypeScript what type of value a variable will refer to&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We tell typescript the type&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Type Inference
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Typescript tries to figure out what type of value a variable refers to&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Typescript guesses the type&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;The type annotation system is kind of at odds with the type inference, so we are going to first understand type annotations and then come along and understand how type inference comes into play.&lt;/p&gt;

&lt;p&gt;To make things a little bit more complicated, know that these two different features apply slightly differently to&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's first talk about how they are applied to Variables, By Examples&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this simple example &lt;strong&gt;:number&lt;/strong&gt; is type annotation.&lt;/p&gt;

&lt;p&gt;If we were to set the value of apples to a boolean we would get an error in  this case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Error: Type 'boolean' is not assignable to type 'number'.ts(2322)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumdgh57fvdwnjbj33ntr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumdgh57fvdwnjbj33ntr.png" alt="Image description" width="602" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;apples&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;apples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;asdas
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Type 'string' is not assignable to type 'number'.ts(2322)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq617r9iwg7brxjwnvu6i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq617r9iwg7brxjwnvu6i.png" alt="Image description" width="513" height="140"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;banana&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// type inference&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;banana&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="c1"&gt;// type annotation&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;banana&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;// type annotation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the declaration and initialization are on the same line without type annotation, typescript will figure out the type of variable for us&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Variable declaration]      [Variable initialization]
     const        color   =               red
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Type inference&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;point&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Type annotation&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;point&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Type inference&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Type annotation&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// [(i: number) =&amp;gt; void] is the annotation here&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When to use annotations with functions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function that returns 'any' type
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"x": 10, "y": 20}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coordinates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;coordinates&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {x:10, y:20}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to understand how JSON.parse works for different values&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Passed Value&lt;/th&gt;
&lt;th&gt;JSON.parse()&lt;/th&gt;
&lt;th&gt;Return Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;'false'&lt;/td&gt;
&lt;td&gt;JSON.parse()&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;'4'&lt;/td&gt;
&lt;td&gt;JSON.parse()&lt;/td&gt;
&lt;td&gt;number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;'{"value:5"}'&lt;/td&gt;
&lt;td&gt;JSON.parse()&lt;/td&gt;
&lt;td&gt;{value:name}&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;'{"name":"alex"}'&lt;/td&gt;
&lt;td&gt;JSON.parse()&lt;/td&gt;
&lt;td&gt;{name:string}&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Typscript decides to set return type to any, meaning it has no idea what type will be returned.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why and when to use type annotation or type inference
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Type inference
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When we declare a variable on one line then initialize it later&lt;/li&gt;
&lt;li&gt;When we want a variable to have a type that cant be inferred&lt;/li&gt;
&lt;li&gt;When a function returns the 'any' type and we need to clarify the value&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Type inference
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Always&lt;/li&gt;
&lt;li&gt;When we  declare a variable on one line and initialize it later&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets wrap the first part of type annotations and type inference in typescript. We will discuss it further in next post. 💯&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting Started with TypeScript: Types</title>
      <dc:creator>youxufkhan</dc:creator>
      <pubDate>Sun, 12 May 2024 19:57:20 +0000</pubDate>
      <link>https://dev.to/youxufkhan/getting-started-with-typescript-types-4ono</link>
      <guid>https://dev.to/youxufkhan/getting-started-with-typescript-types-4ono</guid>
      <description>&lt;h2&gt;
  
  
  Type
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is Type?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Easy way to refer to different properties + functions that a value has&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's learn from an example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"red"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What do you see above, it's a string. That's right. But also&lt;br&gt;
It is a value that has all the properties + methods that we assume that a string has &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties + Methods a 'string' has in JS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;charAt(), charCodeAt(), concat(), includes(), endsWith(), indexOf(), lastlndexOf(), localeCompare(), match(), length and so on....&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I hope you understand from the above example what a type is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Categories of Types
&lt;/h2&gt;

&lt;p&gt;In the world of typescript there are two different categories of types.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Primitive Types&lt;/li&gt;
&lt;li&gt;Object Types&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Primitive Types
&lt;/h2&gt;

&lt;p&gt;Primitive types are all the basic types you might guess.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;number&lt;/li&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;boolean&lt;/li&gt;
&lt;li&gt;symbol&lt;/li&gt;
&lt;li&gt;void&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Object Types
&lt;/h2&gt;

&lt;p&gt;These are any types you create or any other types that are built into language itself.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;functions&lt;/li&gt;
&lt;li&gt;classes&lt;/li&gt;
&lt;li&gt;arrays &lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why do we care about types?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Types are used by the Typescript Compiler to analyze our code for errors&lt;/li&gt;
&lt;li&gt;Types allow other engineers to understand what values are flowing around our codebase&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Examples of Types&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;today&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I created a variable that is an instance of a Date object, if I hover of that variable my code editor will tell me the type of value this variable is pointing at.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const today: Date&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Typescript can now use this information to decide what we can do with this variable. For example if we use this variable and put a dot at the end, I will see my autocomplete pop up here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcuz8tug0qhl3niw75hkw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcuz8tug0qhl3niw75hkw.png" alt="Typescript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is listing out all the different functions and properties a Date object has. Typescript knows that because it has internal definition of what a Date is.&lt;/p&gt;

&lt;p&gt;Similarly if we try to reference a value that a doesn't exist in the Date object, we will immediately see an error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffnwpm0xunu1oskhitb3v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffnwpm0xunu1oskhitb3v.png" alt="Typescript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets create a plain JavaScript Object.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;getAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If I hover over the variable now, it will show all the properties and the method the object has.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4z4bbessekg6uwfh5bsg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4z4bbessekg6uwfh5bsg.png" alt="Typescript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope by these examples you have the basic idea of types in TypeScript. We will discuss more about each of these in the later posts.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>learning</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Getting Started with TypeScript: A Quick Introduction From JavaScript to TypeScript!</title>
      <dc:creator>youxufkhan</dc:creator>
      <pubDate>Thu, 02 May 2024 17:29:08 +0000</pubDate>
      <link>https://dev.to/youxufkhan/getting-started-with-typescript-a-quick-introduction-from-javascript-to-typescript-d4f</link>
      <guid>https://dev.to/youxufkhan/getting-started-with-typescript-a-quick-introduction-from-javascript-to-typescript-d4f</guid>
      <description>&lt;p&gt;As I dive into mastering TypeScript this month, I'll be sharing my journey here, keeping it concise and easy to follow. So, let's kick things off with the very basics. I'm assuming you have a basic grasp of JavaScript.&lt;/p&gt;

&lt;p&gt;Here's a short JavaScript snippet to start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
        The todo with ID: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
        has a title of: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
        is it finished?: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
    `&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple, right? This code just sends an HTTP request using axios and fetches a single todo object from the &lt;a href="https://jsonplaceholder.typicode.com/"&gt;jsonplaceholder&lt;/a&gt; API.&lt;/p&gt;

&lt;p&gt;Now, let's rewrite this in basic TypeScript. First, we can use ES6 module syntax to import axios:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll define a type for the url variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, onto the main part of our code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Todo&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
        The todo with ID: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
        has a title of: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
        is it finished?: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
    `&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice in the above snippet, we've assigned the response data to the todo variable but as Todo. You might be wondering, what's Todo? Well, here's where interfaces come into play. We'll explicitly define a Todo interface:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Todo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! Here's how it all looks finally in TypeScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Todo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Todo&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
        The todo with ID: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
        has a title of: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
        is it finished?: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
    `&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we wrap up, let's quickly highlight the core differences we introduced in the TypeScript version of our code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type Annotations&lt;/strong&gt;: We added type annotations to variables, enhancing code clarity and catching potential errors early.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interface Definition&lt;/strong&gt;: Introducing the Todo interface allowed us to specify the structure of our data, promoting better code organization and type safety.&lt;/p&gt;

&lt;p&gt;In this post, I started with a simple JavaScript snippet fetching data from an API using axios. Then, we gradually migrated it to TypeScript, introducing some of the basic syntax of TypeScript.&lt;/p&gt;

&lt;p&gt;Don't worry if you don't understand some of the terminologies or concepts used here; this is just a short introduction post. In the next post, we'll dive into basic concepts and terminologies to ensure everyone's on the same page. Stay tuned for more TypeScript adventures!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
