<?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>Forem: Muhammad Chandra Bintang Mahaputra</title>
    <description>The latest articles on Forem by Muhammad Chandra Bintang Mahaputra (@muhammad_chandrabintang).</description>
    <link>https://forem.com/muhammad_chandrabintang</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%2F2960301%2Fa8a7be38-0089-4cf2-aa79-0a9110ca275f.png</url>
      <title>Forem: Muhammad Chandra Bintang Mahaputra</title>
      <link>https://forem.com/muhammad_chandrabintang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/muhammad_chandrabintang"/>
    <language>en</language>
    <item>
      <title>Building a CI/CD Pipeline Using GitHub Actions for Deployment to Vercel</title>
      <dc:creator>Muhammad Chandra Bintang Mahaputra</dc:creator>
      <pubDate>Mon, 05 May 2025 15:31:26 +0000</pubDate>
      <link>https://forem.com/muhammad_chandrabintang/building-a-cicd-pipeline-using-github-actions-for-deployment-to-vercel-6po</link>
      <guid>https://forem.com/muhammad_chandrabintang/building-a-cicd-pipeline-using-github-actions-for-deployment-to-vercel-6po</guid>
      <description>&lt;p&gt;As developers, we’ve all heard the term DevOps—a combination of practices that aim to bridge the gap between development and operations. The goal? Deliver software faster, more reliably, and with better collaboration between teams. One key part of this is CI/CD.&lt;/p&gt;

&lt;p&gt;CI/CD stands for Continuous Integration and Continuous Delivery/Deployment. It’s all about automating the steps that run when you push changes to your code repository. With CI/CD, you can build, test, and deploy your app in one seamless, automated process.&lt;/p&gt;

&lt;p&gt;In this article, we’ll walk through setting up a CI/CD pipeline using GitHub Actions. And in the final stage, we’ll deploy the app to Vercel, so it’s live and accessible to everyone.&lt;/p&gt;

&lt;p&gt;Let’s dive into the code and get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Build Angular Project
&lt;/h2&gt;

&lt;p&gt;First, make sure Angular CLI is installed globally with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create a new Angular project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new github-actions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can choose your preferred setup. In my case, I went with CSS for styling and turned off Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering). The project structure will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fe5zjxmu3hiwudg5z17dq.png" class="article-body-image-wrapper"&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%2Farticles%2Fe5zjxmu3hiwudg5z17dq.png" alt="Image description" width="616" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, move into the project directory and run project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom—you should see your project running in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create .yaml File
&lt;/h2&gt;

&lt;p&gt;Inside your Angular project, create a new folder called .github, and inside it, add a folder named workflows. Now, create two files in the workflows folder: development.yaml and production.yaml.&lt;/p&gt;

&lt;p&gt;development.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Production

env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}


on:
  push:
    branches:
      - main

jobs:

  Deploy-Production:
    runs-on: ubuntu-latest
    steps:

        - uses: actions/checkout@v3

        - name: Installation Vercel
          run: npm i -g vercel

        - name: Pull vercel environment
          run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

        - name: Build project
          run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

        - name: Deploy project
          run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;production.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Production

env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

on:
  push:
    branches:
      - main

jobs:
  Test:
    runs-on: ubuntu-latest
    steps:

        - uses: actions/checkout@v3

        - uses: actions/setup-node@v3
          with:
            node-version: 18

        - run: npm ci
        - run: npm run test:production

  Deploy-Production:
    runs-on: ubuntu-latest
    steps:

        - uses: actions/checkout@v3

        - name: Installation Vercel
          run: npm i -g vercel

        - name: Pull vercel environment
          run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

        - name: Build project
          run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

        - name: Deploy project
          run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create GitHub Repo and Push Your Project
&lt;/h2&gt;

&lt;p&gt;Once your .yaml files are set up, go ahead and create a new GitHub repository and push your project to it.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fmo18o1d1olhegn98hi14.png" class="article-body-image-wrapper"&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%2Farticles%2Fmo18o1d1olhegn98hi14.png" alt="Image description" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Up Vercel Project
&lt;/h2&gt;

&lt;p&gt;Log in to Vercel, go to Account Settings, then navigate to the Tokens tab. Create a new token—you’ll need it for GitHub integration.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fwal0wve96gwynt51r5wj.png" class="article-body-image-wrapper"&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%2Farticles%2Fwal0wve96gwynt51r5wj.png" alt="Image description" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Vercel Secrets to GitHub
&lt;/h2&gt;

&lt;p&gt;In your GitHub repo, go to Settings &amp;gt; Secrets and variables &amp;gt; Actions. Add a new secret named VERCEL_TOKEN and paste the token you generated on Vercel.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2F53d2107icsi7jde6jurv.png" class="article-body-image-wrapper"&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%2Farticles%2F53d2107icsi7jde6jurv.png" alt="Image description" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Vercel CLI Locally
&lt;/h2&gt;

&lt;p&gt;You’ll need the Vercel CLI to get VERCEL_ORG_ID and VERCEL_PROJECT_ID. Start by installing it globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g vercel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then log in to Vercel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vercel login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose your preferred login method, and once you're in, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vercel link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a .vercel folder containing project.json. Inside that file, you’ll find both VERCEL_ORG_ID and VERCEL_PROJECT_ID.&lt;/p&gt;

&lt;p&gt;Add those two as secrets in GitHub just like you did with VERCEL_TOKEN.&lt;/p&gt;

&lt;p&gt;So in total, you should now have these three secrets:&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2F2bt8t45jon2zexh6cv4n.png" class="article-body-image-wrapper"&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%2Farticles%2F2bt8t45jon2zexh6cv4n.png" alt="Image description" width="800" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Dev Branch and Test
&lt;/h2&gt;

&lt;p&gt;Create a new branch (e.g., dev), make some changes, and push it. The development.yaml workflow will run automatically. If everything’s set up right, you’ll see a successful build like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fhldu6hvkxf1uge55aaay.png" class="article-body-image-wrapper"&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%2Farticles%2Fhldu6hvkxf1uge55aaay.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge to Main for Production
&lt;/h2&gt;

&lt;p&gt;After you’ve tested your changes and everything looks good, merge your branch into main and push. This will trigger the production workflow and automatically deploy your changes to Vercel.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fasnir9ndzrviz7fnd664.png" class="article-body-image-wrapper"&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%2Farticles%2Fasnir9ndzrviz7fnd664.png" alt="Image description" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you run into test errors, double-check your spec files to ensure your tests are running as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check Your Vercel Project
&lt;/h2&gt;

&lt;p&gt;Your project should now appear in your Vercel dashboard:&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2F70ru8x1l8r1vxdntvsqa.png" class="article-body-image-wrapper"&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%2Farticles%2F70ru8x1l8r1vxdntvsqa.png" alt="Image description" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And inside your Vercel project:&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Farticles%2Fy0vpj94zp60t9tbr337c.png" class="article-body-image-wrapper"&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%2Farticles%2Fy0vpj94zp60t9tbr337c.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using GitHub Actions to build CI/CD pipelines makes your DevOps flow cleaner and more efficient. With automation in place, you can build, test, and deploy your app without hassle.&lt;/p&gt;

&lt;p&gt;I hope this tutorial helped you get the hang of it. Thanks for sticking around—now go build something awesome!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Clean Code Is a Habit, Not a Talent</title>
      <dc:creator>Muhammad Chandra Bintang Mahaputra</dc:creator>
      <pubDate>Sun, 04 May 2025 16:59:57 +0000</pubDate>
      <link>https://forem.com/muhammad_chandrabintang/clean-code-is-a-habit-not-a-talent-2l01</link>
      <guid>https://forem.com/muhammad_chandrabintang/clean-code-is-a-habit-not-a-talent-2l01</guid>
      <description>&lt;p&gt;A smart developer once said: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Clean code isn’t some magic skill — it’s just a habit you build over time."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And guess what? You can totally build that habit.&lt;/p&gt;

&lt;p&gt;Clean code means writing code that's clear, organized, and easy to work with. It makes your life (and your teammates’ lives) way easier. But let’s be honest — how many times have we said, “I’ll clean this up later”?&lt;/p&gt;

&lt;p&gt;Here’s the truth:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There’s never a perfect time to refactor&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Messy code turns into technical debt — and sooner or later, you’ll have to deal with it. It’s better to start clean than to fix bugs forever later.&lt;/p&gt;

&lt;p&gt;Writing clean code isn’t as hard as it sounds. Actually, it can feel really natural once you get the hang of it. Think of it like building something with care — not just typing stuff out.&lt;/p&gt;

&lt;p&gt;Here are a few simple tips to help you write cleaner code:&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Keep Things Short
&lt;/h2&gt;

&lt;p&gt;Don’t stuff too much into one file. Break things up. If you're reusing the same logic in multiple places, put it in a separate utility file.&lt;/p&gt;

&lt;p&gt;For example, say you always need to generate a running number for a table ID. Instead of repeating that logic everywhere, just make a helper function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function runningNumber(id: number): string {
  return `CB${id}`;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then call it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const id = this.specialServices.runningNumber(this.listData.id);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you’ve got one clean line that does the job — and you only need to update it in one place if anything changes. This keeps your code short.&lt;/p&gt;

&lt;p&gt;Some devs even set a file size limit (like 200–400 lines), but honestly, the smaller, the better.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Reuse Components
&lt;/h2&gt;

&lt;p&gt;If a part of your app (like a modal, breadcrumb, or table) shows up in multiple places, make it a shared component — with its own HTML and logic.&lt;/p&gt;

&lt;p&gt;Then you can reuse it anywhere by just passing in the content you want. It saves time and keeps things clean.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Name Your Variables Well
&lt;/h2&gt;

&lt;p&gt;Good names make a huge difference.&lt;/p&gt;

&lt;p&gt;Avoid stuff like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = 12;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That tells you nothing. Instead, try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userAge = 12;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it’s instantly clear what that value means.&lt;/p&gt;




&lt;p&gt;I’ll explain it in more detail in the refactoring article, so stay tuned!&lt;/p&gt;

&lt;p&gt;Just remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Clean code is a habit, not a talent.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once it becomes second nature, everything gets smoother.&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Avoid Redundant Properties in TypeScript Interfaces</title>
      <dc:creator>Muhammad Chandra Bintang Mahaputra</dc:creator>
      <pubDate>Tue, 29 Apr 2025 16:24:29 +0000</pubDate>
      <link>https://forem.com/muhammad_chandrabintang/avoid-redundant-properties-in-typescript-interfaces-284i</link>
      <guid>https://forem.com/muhammad_chandrabintang/avoid-redundant-properties-in-typescript-interfaces-284i</guid>
      <description>&lt;p&gt;You know that feeling when you meet someone and they forget your name? Kinda annoying or awkward, right? That’s pretty much what it’s like when you're working with data but don’t know its type—it’s like the data doesn’t have a name. So, before we jump into how to cut down on redundancy in TypeScript interfaces, let’s talk about why interfaces matter in the first place, what they’re for, and how to use them the right way.&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;
}

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

&lt;/div&gt;



&lt;p&gt;Interfaces help us understand the data we get from the backend or send from the frontend, so we can work with it the right way. As your project grows, it’s easy to make mistakes—like treating a string as a number, or the other way around. That’s when bugs pop up and things get frustrating real quick. Most of the time, it’s because the data isn’t clearly defined. That’s why every field should have a proper type, so you know exactly how to use it.&lt;/p&gt;

&lt;p&gt;We often get data in JSON format that looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "lyla",
  "age": 12
}

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

&lt;/div&gt;



&lt;p&gt;Now, a lazy way to handle this is by assigning the data to a variable with the any type—basically telling TypeScript, “I don’t know what this is.”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let student: any;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem? You have no clue what’s actually in that object. So when you do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("my student:", student.nickname);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It won’t throw an error—even though the nickname doesn’t exist—because any disables type checking. Instead, try this:&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;
}

let student: User;
student = { name: 'lyla', age: 12 };
console.log(student.email); // ❌ TypeScript will throw an error here
console.log(student.name);  // ✅ This works fine

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

&lt;/div&gt;



&lt;p&gt;With an interface, TypeScript can warn you if you’re trying to access something that doesn’t exist, helping you catch bugs early.&lt;/p&gt;

&lt;p&gt;I hope my explanation about interfaces was easy to follow. Now let’s move on to how we can reduce redundant properties in TypeScript interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  1.   Inherit Shared Properties
&lt;/h2&gt;

&lt;p&gt;In a real project, it’s pretty common to deal with different data types that share some of the same properties. For example, let’s say you have data for both students and lecturers. They both have name, age, and email—but the lecturer also has an extra property like phone_number.&lt;/p&gt;

&lt;p&gt;A lot of beginner TypeScript developers might write something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Student {
  name: string;
  age: number;
  email: string;
}

interface Lecturer  {
  name: string;
  age: number;
  email: string;
  phone_number: number;
}

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

&lt;/div&gt;



&lt;p&gt;Now, this isn’t technically wrong—it’ll work just fine. But it’s not the cleanest way to write it. You can make it better (and DRY) like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Student {
  name: string;
  age: number;
  email: string;
}

interface Lecturer extends Student {
  phone_number: number;
}

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

&lt;/div&gt;



&lt;p&gt;This way, you avoid repeating code and make your interfaces easier to maintain. &lt;/p&gt;

&lt;h2&gt;
  
  
  2.   Use utility (pick ,omit, etc)
&lt;/h2&gt;

&lt;p&gt;Let’s say you only need the name property from the Student interface. Instead of creating a whole new interface, you can use TypeScript’s Pick utility:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MandatoryProperties = Pick&amp;lt;Student, "name"&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Pick utility lets you grab specific properties from an existing interface—super useful when you only need part of the data structure.&lt;/p&gt;

&lt;p&gt;On the flip side, if there’s a property you don’t need, you can use the Omit utility:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MandatoryProperties = Omit&amp;lt;Student, "email"&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Omit removes specific properties from an interface. So in this case, you get a type with everything from Student except the email. These utilities help keep your code cleaner and avoid unnecessary duplication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Intersection (&amp;amp;)
&lt;/h2&gt;

&lt;p&gt;You can also combine two interfaces using an intersection—this can really speed things up and keep your code neat.&lt;br&gt;
&lt;/p&gt;

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

interface Lecturer {
  nip: string;
}

type User = Student &amp;amp; Lecturer;

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

&lt;/div&gt;



&lt;p&gt;Now User has all the properties from both Student and Lecturer. Pretty handy, right?&lt;/p&gt;

&lt;p&gt;So those are some simple tips for TypeScript developers to cut down on redundant properties and write code that’s cleaner, more efficient, and easier to manage.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>cleancode</category>
      <category>dry</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
