<?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: mashayeakh islam</title>
    <description>The latest articles on DEV Community by mashayeakh islam (@mashayeakh_islam_2666f2c3).</description>
    <link>https://dev.to/mashayeakh_islam_2666f2c3</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%2F1561540%2F022152b3-879b-431f-be38-71825cfc9392.jpg</url>
      <title>DEV Community: mashayeakh islam</title>
      <link>https://dev.to/mashayeakh_islam_2666f2c3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mashayeakh_islam_2666f2c3"/>
    <language>en</language>
    <item>
      <title>🚀 Type Alias in TypeScript: Why I Use Them Every Day (And How They Compare to Interfaces)</title>
      <dc:creator>mashayeakh islam</dc:creator>
      <pubDate>Thu, 20 Nov 2025 06:20:06 +0000</pubDate>
      <link>https://dev.to/mashayeakh_islam_2666f2c3/type-alias-in-typescript-why-i-use-them-every-day-and-how-they-compare-to-interfaces-399n</link>
      <guid>https://dev.to/mashayeakh_islam_2666f2c3/type-alias-in-typescript-why-i-use-them-every-day-and-how-they-compare-to-interfaces-399n</guid>
      <description>&lt;p&gt;&lt;strong&gt;If you’ve already dipped your toes into TypeScript, you’ve probably met that one feature everyone talks about but no one fully explains at the start.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🧩 What Is a Type Alias?
&lt;/h2&gt;

&lt;p&gt;A type alias is basically giving a nickname to a type.&lt;br&gt;
Instead of rewriting the same structure again and again, you wrap it inside a type and reuse it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A basic explanation?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of it like giving your WiFi a name.&lt;br&gt;
The internet was always there, but naming it “DragonSlayer-5G” makes life easier.&lt;/p&gt;

&lt;p&gt;Here’s a simple example from my playground:&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 alias&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&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;contactNo&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;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;division&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;city&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="p"&gt;};&lt;/span&gt;
  &lt;span class="nl"&gt;gender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;male&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;female&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&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;user1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mashayeakh&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;contactNo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;01777&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;division&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dhaka&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dhaka&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;gender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;male&lt;/span&gt;&lt;span class="dl"&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;user1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;😄 Why I Like Type Aliases&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When I'm structuring data models, a type alias feels natural. It’s straightforward and doesn’t pretend to be anything else. It just bundles types together and says, “Bro, use me wherever you want.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can even reuse it across multiple variables:&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;user2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Emma&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;contactNo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;017988&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;division&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;gender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;female&lt;/span&gt;&lt;span class="dl"&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;user2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This alone saves you from rewriting properties all day.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  🍕 Type Alias for Functions (Tasty Feature)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Types aren’t only for objects. You can name a function’s signature as well.&lt;/strong&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;type&lt;/span&gt; &lt;span class="nx"&gt;AddFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&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;num2&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="kr"&gt;number&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;add&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AddFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&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="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&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;blockquote&gt;
&lt;p&gt;_ This makes your functions consistent and self-documented.&lt;br&gt;
It also prevents “creative” arguments like strings, booleans, or emotions entering your math functions._&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  ⚔️ Intersection Types (Combining Multiple Types)
&lt;/h2&gt;

&lt;p&gt;Sometimes you want to combine different structures.&lt;br&gt;
Type alias handles that with the &amp;amp; operator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Like merging two Marvel characters but without copyright issues.&lt;/strong&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;type&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&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;age&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="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;UserWithRole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;Role&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;user1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UserWithRole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MR.X&lt;/span&gt;&lt;span class="dl"&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;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&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;user1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Here, &lt;code&gt;UserWithRole&lt;/code&gt;becomes a new super-type that contains everything.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  🆚 Type vs Interface — The Battle That Never Ends
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;If you Google &lt;em&gt;“type vs interface TypeScript”&lt;/em&gt;, you’ll find 500 different answers.&lt;br&gt;
Some swear by &lt;code&gt;interface&lt;/code&gt;. Others defend &lt;code&gt;type&lt;/code&gt;like it's their first-born child.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me explain it cleanly.&lt;/p&gt;

&lt;p&gt;✔ Interfaces are designed specifically for object shapes&lt;br&gt;
✔ Types are more flexible — they work with primitives, unions, tuples, functions, and objects too&lt;/p&gt;

&lt;p&gt;Both can describe objects, but types can do much more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s compare both with the same example.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🧱 Using Interface
&lt;/h2&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;IUser&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&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;age&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="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;IUserWithRole&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;IUser&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&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;user3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IUserWithRole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MIP&lt;/span&gt;&lt;span class="dl"&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;123&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&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;user3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Interfaces shine when you need extension and structured modeling.&lt;br&gt;
They support declaration merging, are extendable, and feel very OOP-friendly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  🔗 Using Type Alias
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&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;age&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="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;UserWithRole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Types don’t use &lt;code&gt;extends&lt;/code&gt;, but the &lt;code&gt;&amp;amp;&lt;/code&gt; operator does the same job.&lt;br&gt;
The difference is more about preference and convenience.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  🥊 So When Should You Use What?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use type when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need unions (string | number)&lt;/li&gt;
&lt;li&gt;You need intersections&lt;/li&gt;
&lt;li&gt;You define primitives (type ID = string | number)&lt;/li&gt;
&lt;li&gt;You define function signatures&lt;/li&gt;
&lt;li&gt;You want one flexible tool for everything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use interface when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are modeling objects heavily&lt;/li&gt;
&lt;li&gt;You want declaration merging&lt;/li&gt;
&lt;li&gt;You prefer OOP-style extensions&lt;/li&gt;
&lt;li&gt;You want a consistent structure across your app&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Both work. Both are valid.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;TypeScript doesn't judge you. Your team might, though.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  😄 A Tiny Joke Before You Go
&lt;/h2&gt;

&lt;p&gt;TypeScript developers be like:&lt;/p&gt;

&lt;p&gt;“I don’t have trust issues. I just don’t trust &lt;code&gt;any&lt;/code&gt;.”&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;If you’re learning TypeScript, mastering &lt;code&gt;type&lt;/code&gt;and &lt;code&gt;interface&lt;/code&gt;early will make your life easier.&lt;br&gt;
These features help you write safer code and help your future teammates avoid headaches.&lt;/p&gt;

&lt;p&gt;This post is part of my TypeScript learning journey, and I hope it helps someone who’s just getting started.&lt;/p&gt;

&lt;p&gt;If you're a beginner, keep exploring. If you're experienced, feel free to roast my examples in the comments.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Written by &lt;strong&gt;&lt;em&gt;Masayeakh&lt;/em&gt;&lt;/strong&gt; full stack dev sharing his TypeScript journey.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>programming</category>
    </item>
    <item>
      <title>🚀 4 TypeScript Concepts That Made Me Write Cleaner Code</title>
      <dc:creator>mashayeakh islam</dc:creator>
      <pubDate>Tue, 28 Oct 2025 08:18:32 +0000</pubDate>
      <link>https://dev.to/mashayeakh_islam_2666f2c3/4-typescript-concepts-that-made-me-write-cleaner-code-42m9</link>
      <guid>https://dev.to/mashayeakh_islam_2666f2c3/4-typescript-concepts-that-made-me-write-cleaner-code-42m9</guid>
      <description>&lt;p&gt;Hey everyone 👋,&lt;br&gt;
I’m Masayeakh, a &lt;strong&gt;full stack dev&lt;/strong&gt; from Bangladesh currently learning TypeScript to level up my JavaScript skills.&lt;/p&gt;

&lt;p&gt;After diving deeper into TypeScript this week, I learned a few features that completely changed how I think about code — &lt;strong&gt;Union Types, Tuples, Enums, and Interfaces.&lt;/strong&gt;&lt;br&gt;
Let’s go through them one by one 👇&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔗 1. Union Types — When You Don’t Know What’s Coming&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sometimes you don’t know if a value will be a string or a number.&lt;br&gt;
That’s where &lt;strong&gt;Union Types&lt;/strong&gt; shine.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let score: number | string = 33;
score = "55";

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;TypeScript now lets score accept both numbers and strings — without losing type safety.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here’s a more practical example 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type User = { name: string; email: string; id: number; };
type Admin = { adminName: string; email: string; id: number; };

let person: User | Admin = { name: "Masayeakh", email: "m@gmail.com", id: 101 };
person = { adminName: "Masayeakh", email: "m@admin.com", id: 101 };

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧠 Lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Union types make your code flexible when multiple data types or structures are possible — like APIs, roles, or IDs.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;🧱 2. Tuples — Arrays That Follow Strict Rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tuples define &lt;strong&gt;fixed length and data type order&lt;/strong&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user: [string, number] = ["Jhon", 22];

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;If you try to swap types or add another element, TypeScript will yell at you 😅&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But you can even make them readonly:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type UserInfo = readonly [string, number];
const user1: UserInfo = ["Masayeakh", 25];

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

&lt;/div&gt;



&lt;p&gt;🧠 Lesson:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Use tuples when you need ordered, predictable data — like &lt;br&gt;
&lt;code&gt;[username, id],&lt;/code&gt;&lt;br&gt;
&lt;code&gt;[lat, long],&lt;/code&gt; etc.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;🪑 3. Enums — Human-Readable Constant Values&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Instead of using magic numbers or strings everywhere, enums make your code more readable.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum SeatChoice {
  AISLE,
  MIDDLE,
  WINDOW,
}

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

&lt;/div&gt;



&lt;p&gt;Now you can write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let mySeat: SeatChoice = SeatChoice.MIDDLE;

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;You can even customize them 👇&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum SeatChoice2 {
  AISLE = 10,
  MIDDLE = 20,
  WINDOW = 30,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧠 Lesson:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Enums make constants easier to manage, especially for configurations or fixed categories.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;💡 4. Interfaces — The Blueprint for Objects&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interfaces tell TypeScript what structure an object should follow.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface User {
  name: string;
  age: number;
  isActive: boolean;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, any object claiming to be a &lt;code&gt;User&lt;/code&gt;must match this shape.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can even define functions inside:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface MathOp {
  val1: number;
  val2: number;
  operation(): number;
}

let result: MathOp = {
  val1: 23,
  val2: 32,
  operation() {
    return this.val1 + this.val2;
  },
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧠 Lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Interfaces make code scalable — especially when working on large applications or teams.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;🎯 Final Thoughts&lt;/strong&gt;&lt;br&gt;
Each week I learn something that makes me respect TypeScript more.&lt;br&gt;
This language doesn’t just help avoid bugs — it &lt;strong&gt;forces me to think clearly about structure, safety, and intent.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next up, I’ll explore &lt;strong&gt;Generics and Type Inference&lt;/strong&gt; — the real brain stretchers 🧠💪&lt;/p&gt;

&lt;p&gt;If you’re also learning TypeScript, let’s connect and share progress!&lt;br&gt;
Drop your profile or comment below 💬&lt;/p&gt;




&lt;p&gt;Written by &lt;strong&gt;Masayeakh — full stack dev&lt;/strong&gt; sharing his TypeScript journey.&lt;/p&gt;

</description>
      <category>fullstack</category>
      <category>typescript</category>
      <category>learning</category>
      <category>programming</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>mashayeakh islam</dc:creator>
      <pubDate>Mon, 27 Oct 2025 12:25:41 +0000</pubDate>
      <link>https://dev.to/mashayeakh_islam_2666f2c3/-2gnb</link>
      <guid>https://dev.to/mashayeakh_islam_2666f2c3/-2gnb</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/mashayeakh_islam_2666f2c3" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1561540%2F022152b3-879b-431f-be38-71825cfc9392.jpg" alt="mashayeakh_islam_2666f2c3"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/mashayeakh_islam_2666f2c3/5-things-i-learned-in-my-first-week-of-typescript-51md" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;5 Things I Learned in My First Week of TypeScript&lt;/h2&gt;
      &lt;h3&gt;mashayeakh islam ・ Oct 27&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#fullstack&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#learninginpublic&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>programming</category>
      <category>typescript</category>
      <category>fullstack</category>
      <category>learninginpublic</category>
    </item>
    <item>
      <title>5 Things I Learned in My First Week of TypeScript</title>
      <dc:creator>mashayeakh islam</dc:creator>
      <pubDate>Mon, 27 Oct 2025 05:14:20 +0000</pubDate>
      <link>https://dev.to/mashayeakh_islam_2666f2c3/5-things-i-learned-in-my-first-week-of-typescript-51md</link>
      <guid>https://dev.to/mashayeakh_islam_2666f2c3/5-things-i-learned-in-my-first-week-of-typescript-51md</guid>
      <description>&lt;p&gt;Hey everyone! I’m Masayeakh, a &lt;strong&gt;Full stack Dev&lt;/strong&gt; from Bangladesh who’s learning TypeScript to level up my skills.&lt;/p&gt;

&lt;p&gt;Last week, I started my TypeScript journey — and wow, it’s been an exciting ride so far! From type safety to cleaner code, I can already see why so many developers love it.&lt;/p&gt;

&lt;p&gt;In this post, I’ll share 5 simple but powerful lessons I learned in my first week of TypeScript. If you’re starting out like me, this might help you avoid confusion and learn faster 🚀&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;1. TypeScript Catches Errors Before You Run the Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In JavaScript, many bugs show up only when you run your code.&lt;br&gt;
But in TypeScript, errors appear while you’re writing.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age: number = "25"; // ❌ Type error: Type 'string' is not assignable to type 'number'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&amp;gt; It’s like having a super strict but helpful teacher who doesn’t let you make silly mistakes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;2. Defining Function Types Keeps Your Code Clean&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can define &lt;strong&gt;what type of data a function expects&lt;/strong&gt; and what it returns.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a: number, b: number): number {
  return a + b;
}

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&amp;gt; If you accidentally return a string or forget a parameter, TypeScript immediately warns you.&lt;br&gt;
It makes functions predictable — which is great for big projects.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧱 3. Objects and Type Aliases Make Life Easier&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Instead of writing object types again and again, you can use type aliases.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type User = {
  name: string;
  age: number;
  email?: string; // optional property; email will be added if used otherwise blank;
};

const user1: User = { name: "Masayeakh", age: 25 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&amp;gt; This makes code look cleaner, especially when building apps with many components.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔒 4. Readonly Properties Prevent Unwanted Changes&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;If you don’t want something to be modified, just make it &lt;code&gt;readonly&lt;/code&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Config = {
  readonly apiUrl: string;
};

const config: Config = { apiUrl: "https://api.example.com" };
config.apiUrl = "https://newurl.com"; // ❌ Error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&amp;gt; This is small but super useful in team projects where mistakes happen.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔗 5. Union Types Are a Game-Changer&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Union types let a variable hold more than one type.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getId(id: number | string) {
  return id;
}

getId(123);
getId("abc");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&amp;gt; They’re great when your data can come in multiple forms (like user IDs or API responses).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My first week with TypeScript taught me one thing — &lt;strong&gt;type safety = peace of mind.&lt;/strong&gt;&lt;br&gt;
It doesn’t just catch bugs early; it helps me write more confident, organized code.&lt;/p&gt;

&lt;p&gt;Next, I’ll dive into &lt;strong&gt;interfaces, generics, and TypeScript with React&lt;/strong&gt; — can’t wait to share that journey too!&lt;/p&gt;

&lt;p&gt;If you’re learning TypeScript as well, let’s connect and grow together 💬&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 About Me&lt;/strong&gt;&lt;br&gt;
I’m a Full Stack Developer learning AI-driven TypeScript, Next.js, and modern web technologies.**&lt;br&gt;
I love building projects, sharing what I learn, and connecting with global devs.&lt;br&gt;
Let’s grow together — both in code and life 🌍💻&lt;/p&gt;

</description>
      <category>programming</category>
      <category>typescript</category>
      <category>fullstack</category>
      <category>learninginpublic</category>
    </item>
  </channel>
</rss>
