Mohamed GhoniemWeb Developer
MohamedGhoniem
  • Work
  • Services
  • Experience
  • Blog
Available
CV
Open to opportunities
WorkServicesExperienceBlogDownload CV
All blogs

© 2026 Mohamed Ghoniem. All rights reserved.

TwitterGitHubLinkedIn
Advanced TypeScript patterns every React dev should know
DesignFrontend
All blogs

Advanced TypeScript patterns every React dev should know

MG
Mohamed Ghoniem
·July 16, 2026·9 min read

Prefer to watch?

This article has a full video walkthrough on YouTube

Watch the same walkthrough on YouTube.

Why static typing matters in complex apps

As applications grow, keeping track of prop interfaces, API responses, and global state becomes prone to human errors. TypeScript acts as a compile-time safety net, documenting your code as you write it.

Advanced patterns to know

Using Discriminated Unions helps construct APIs where the presence of certain props depends on the value of another prop.

typescript
// Example of discriminated union
type ButtonProps = 
  | { variant: 'link'; href: string; children: React.ReactNode }
  | { variant: 'button'; onClick: () => void; children: React.ReactNode };

export function Button(props: ButtonProps) {
  if (props.variant === 'link') {
    return <a href={props.href}>{props.children}</a>;
  }
  return <button onClick={props.onClick}>{props.children}</button>;
}

Using Template Literal Types

Template literal types allow you to build dynamic string values based on specific patterns, which is perfect for theme tokens, spacing values, or event handlers.

On this page9 min left
Why static typing matters in complex appsAdvanced patterns to knowUsing Template Literal Types

Share

On this page9 min left
Why static typing matters in complex appsAdvanced patterns to knowUsing Template Literal Types

Written by

Mohamed Ghoniem

I build fast, responsive web experiences, from pixel-perfect UI to the backend behind it.

Get in touchAll posts
Older postThe complete Next.js SEO checklist for 2025Newer postSmooth page transitions with Framer Motion and Next.js App Router
Keep reading
Building a design system from scratch with Figma tokens & Tailwind
DesignFrontendJuly 16, 2026

Building a design system from scratch with Figma tokens & Tailwind

A practical walkthrough of how I set up a token-driven design system that stays in sync between Figma and code — no plugin lock-in, no manual updates.

MG
Mohamed G.
8 min read
The hidden cost of unoptimized images in Next.js
DesignFrontendJuly 16, 2026

The hidden cost of unoptimized images in Next.js

A practical walkthrough of how I set up a token-driven design system that stays in sync between Figma and code — no plugin lock-in, no manual updates.

MG
Mohamed G.
5 min read
JWT refresh token rotation — the right way
DesignFrontendJuly 16, 2026

JWT refresh token rotation — the right way

A practical walkthrough of how I set up a token-driven design system that stays in sync between Figma and code — no plugin lock-in, no manual updates.

MG
Mohamed G.
6 min read