<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TypeScript on Tech, Games, and Everyday Life – Made Simple</title><link>https://takao.blog/categories/typescript/</link><description>Recent content in TypeScript on Tech, Games, and Everyday Life – Made Simple</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Commentary of Takao</copyright><lastBuildDate>Wed, 10 Jun 2026 00:00:00 +0900</lastBuildDate><atom:link href="https://takao.blog/categories/typescript/index.xml" rel="self" type="application/rss+xml"/><item><title>Strict Type Guarding using TypeScript's NoInfer Utility</title><link>https://takao.blog/web/typescript-unmapped-types-utility/</link><pubDate>Wed, 10 Jun 2026 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-unmapped-types-utility/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-unmapped-types-utility-en.png" alt="Featured image of post Strict Type Guarding using TypeScript's NoInfer Utility" /&gt;&lt;h2 id="the-widening-problem"&gt;The Widening Problem
&lt;/h2&gt;&lt;p&gt;When TypeScript infers types from multiple call-site arguments, it often &lt;strong&gt;widens&lt;/strong&gt; the inferred type to accommodate all candidates. This is usually helpful, but in certain generic scenarios it produces types that are too loose, letting invalid states slip through.&lt;/p&gt;
&lt;p&gt;Consider a function that accepts a default value alongside a specific key:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-typescript" data-lang="typescript"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;function&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;createState&lt;/span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;T&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;extends&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color:#a6e22e"&gt;key&lt;/span&gt;: &lt;span style="color:#66d9ef"&gt;T&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;defaultValue&lt;/span&gt;: &lt;span style="color:#66d9ef"&gt;T&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; { &lt;span style="color:#a6e22e"&gt;key&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;defaultValue&lt;/span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;state&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;createState&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;color&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;blue&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// T inferred as &amp;#34;color&amp;#34; | &amp;#34;blue&amp;#34; — not what we want
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;TypeScript infers &lt;code&gt;T&lt;/code&gt; as &lt;code&gt;&amp;quot;color&amp;quot; | &amp;quot;blue&amp;quot;&lt;/code&gt; instead of constraining &lt;code&gt;defaultValue&lt;/code&gt; to match &lt;code&gt;key&lt;/code&gt;. The result type loses precision for both parameters.&lt;/p&gt;</description></item><item><title>Exporting Proper TypeScript Declaration Files (.d.ts) for NPM</title><link>https://takao.blog/web/typescript-declaration-files-dts/</link><pubDate>Sun, 10 May 2026 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-declaration-files-dts/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-declaration-files-dts-en.png" alt="Featured image of post Exporting Proper TypeScript Declaration Files (.d.ts) for NPM" /&gt;&lt;h2 id="why-declaration-files-matter"&gt;Why Declaration Files Matter
&lt;/h2&gt;&lt;p&gt;When you publish an npm package written in TypeScript, consumers need type information to get IntelliSense and compile-time checking. Without &lt;code&gt;.d.ts&lt;/code&gt; files, your library is effectively typed as &lt;code&gt;any&lt;/code&gt;, defeating the purpose of using TypeScript in the first place.&lt;/p&gt;
&lt;p&gt;Declaration files describe the shape of your exports without shipping the implementation source. They enable tree-shaking, documentation hover tips, and strict type checking in consumer projects.&lt;/p&gt;
&lt;h2 id="generating-dts-files"&gt;Generating .d.ts Files
&lt;/h2&gt;&lt;p&gt;The TypeScript compiler generates declaration files when &lt;code&gt;declaration&lt;/code&gt; is set to &lt;code&gt;true&lt;/code&gt; in &lt;code&gt;tsconfig.json&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Building Complex string Parsers inside TypeScript Type System</title><link>https://takao.blog/web/typescript-template-literal-type-level-parsers/</link><pubDate>Fri, 10 Apr 2026 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-template-literal-type-level-parsers/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-template-literal-type-level-parsers-en.png" alt="Featured image of post Building Complex string Parsers inside TypeScript Type System" /&gt;&lt;h2 id="parsing-at-the-type-level"&gt;Parsing at the Type Level
&lt;/h2&gt;&lt;p&gt;TypeScript&amp;rsquo;s template literal types, combined with recursive conditional types and &lt;code&gt;infer&lt;/code&gt;, allow you to parse and transform string literals entirely within the type system. This is not a runtime parser—it is a compile-time parser that extracts structure from string constants, enabling strongly typed APIs for URL routing, SQL queries, command-line arguments, and more.&lt;/p&gt;
&lt;h2 id="template-literal-types-primer"&gt;Template Literal Types Primer
&lt;/h2&gt;&lt;p&gt;Template literal types can interpolate other types and infer parts of a string.&lt;/p&gt;</description></item><item><title>Branching in TS Type System: Intro to Conditional Types</title><link>https://takao.blog/web/typescript-conditional-types/</link><pubDate>Thu, 15 Jan 2026 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-conditional-types/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-conditional-types-en.png" alt="Featured image of post Branching in TS Type System: Intro to Conditional Types" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;TypeScript&amp;rsquo;s type system is &lt;strong&gt;Turing-complete&lt;/strong&gt;, and one of the key features that unlocks its full power is &lt;strong&gt;conditional types&lt;/strong&gt;. Just like ternary operators in JavaScript (&lt;code&gt;condition ? a : b&lt;/code&gt;), conditional types let you create type-level logic: &lt;code&gt;T extends U ? X : Y&lt;/code&gt;. This enables dynamic, context-aware type resolution.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="basic-syntax"&gt;Basic Syntax
&lt;/h2&gt;&lt;p&gt;A conditional type checks whether a type &lt;strong&gt;extends&lt;/strong&gt; another type:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-typescript" data-lang="typescript"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;type&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;IsString&lt;/span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;T&lt;/span&gt;&amp;gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;T&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;extends&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;string&lt;/span&gt; &lt;span style="color:#f92672"&gt;?&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;true&lt;/span&gt; &lt;span style="color:#f92672"&gt;:&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;false&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;type&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;A&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;IsString&lt;/span&gt;&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;hello&amp;#39;&lt;/span&gt;&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt;; &lt;span style="color:#75715e"&gt;// true
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;type&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;B&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;IsString&lt;/span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;42&lt;/span&gt;&amp;gt;; &lt;span style="color:#75715e"&gt;// false
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The condition &lt;code&gt;T extends U&lt;/code&gt; asks: &amp;ldquo;Is &lt;code&gt;T&lt;/code&gt; assignable to &lt;code&gt;U&lt;/code&gt;?&amp;rdquo; If yes, resolve to the true branch; otherwise, the false branch.&lt;/p&gt;</description></item><item><title>Transforming Types dynamically using Mapped Types</title><link>https://takao.blog/web/typescript-mapped-types/</link><pubDate>Mon, 10 Nov 2025 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-mapped-types/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-mapped-types-en.png" alt="Featured image of post Transforming Types dynamically using Mapped Types" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Mapped types&lt;/strong&gt; let you transform an existing object type by iterating over its keys. Think of them as &lt;code&gt;Array.prototype.map()&lt;/code&gt; but at the &lt;strong&gt;type level&lt;/strong&gt;. The syntax &lt;code&gt;{ [K in keyof T]: T[K] }&lt;/code&gt; creates a new type by applying a transformation to each property of &lt;code&gt;T&lt;/code&gt;. This is how many of TypeScript&amp;rsquo;s built-in utility types work under the hood.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="basic-mapped-type"&gt;Basic Mapped Type
&lt;/h2&gt;&lt;p&gt;The simplest mapped type creates a clone of an existing type:&lt;/p&gt;</description></item><item><title>Type-Safe State Transitions using Discriminated Unions</title><link>https://takao.blog/web/typescript-discriminated-unions/</link><pubDate>Wed, 10 Sep 2025 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-discriminated-unions/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-discriminated-unions-en.png" alt="Featured image of post Type-Safe State Transitions using Discriminated Unions" /&gt;&lt;p&gt;In modern frontend and backend development with TypeScript, ensuring type safety during state transitions is a crucial element in building robust and crash-free applications. When handling asynchronous API communications (such as transitioning between loading, success, and error states) or complex user interactions, ambiguous type definitions can easily lead to unexpected runtime errors.&lt;/p&gt;
&lt;p&gt;In this article, we will explore how to harness the power of &lt;strong&gt;Discriminated Unions&lt;/strong&gt; (also known as Tagged Unions) in TypeScript to manage state safely, elegantly, and with minimum boilerplate.&lt;/p&gt;</description></item><item><title>How to Use Standard Decorators in TypeScript</title><link>https://takao.blog/web/typescript-5-decorations-adoption/</link><pubDate>Sat, 05 Jul 2025 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-5-decorations-adoption/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-5-decorations-adoption-en.png" alt="Featured image of post How to Use Standard Decorators in TypeScript" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;In TypeScript, &lt;strong&gt;decorators&lt;/strong&gt; have long been a key feature, popularized by major frameworks like Angular, NestJS, and TypeORM to manage metadata and dependency injection.&lt;/p&gt;
&lt;p&gt;However, for years, decorators remained an experimental feature (requiring the &lt;code&gt;experimentalDecorators&lt;/code&gt; flag), relying on a legacy proposal that differed from the evolving ECMAScript (JavaScript) standard.&lt;/p&gt;
&lt;p&gt;With the release of TypeScript 5.0, &lt;strong&gt;official support for the standard ECMAScript Decorators (Stage 3/4)&lt;/strong&gt; was introduced. This brings improved type safety and runtime consistency to the decorator syntax. This article explains how to write standard decorators in modern TypeScript.&lt;/p&gt;</description></item><item><title>Creating Powerful String Types with TS Template Literals</title><link>https://takao.blog/web/typescript-template-literal-types/</link><pubDate>Tue, 10 Jun 2025 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-template-literal-types/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-template-literal-types-en.png" alt="Featured image of post Creating Powerful String Types with TS Template Literals" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;TypeScript offers an advanced type system that allows developers to model complex runtime constraints at compile time.&lt;/p&gt;
&lt;p&gt;Among these features, &lt;strong&gt;Template Literal Types&lt;/strong&gt; (introduced in TypeScript 4.1) allow you to define structured string constraints by combining string literals.&lt;/p&gt;
&lt;p&gt;By applying JavaScript&amp;rsquo;s template literal syntax (&lt;code&gt;`hello ${name}`&lt;/code&gt;) to type space, you can enforce safe CSS class name patterns, automate API route mappings, and construct typed design systems. This guide reviews the core patterns of Template Literal Types.&lt;/p&gt;</description></item><item><title>Mastering the TypeScript satisfies Operator</title><link>https://takao.blog/web/typescript-satisfies-operator/</link><pubDate>Mon, 10 Mar 2025 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-satisfies-operator/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-satisfies-operator-en.png" alt="Featured image of post Mastering the TypeScript satisfies Operator" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;Introduced in TypeScript 4.9, the &lt;strong&gt;&lt;code&gt;satisfies&lt;/code&gt; operator&lt;/strong&gt; is a powerful feature designed to improve type safety while preserving developer flexibility.&lt;/p&gt;
&lt;p&gt;However, distinguishing the difference between &lt;code&gt;satisfies&lt;/code&gt;, type annotations (&lt;code&gt;: Type&lt;/code&gt;), and type assertions (&lt;code&gt;as Type&lt;/code&gt;) can be confusing. This guide breaks down the mechanics of the &lt;code&gt;satisfies&lt;/code&gt; operator and shares practical use cases for production codebases.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="1-the-limitation-of-standard-type-annotations-"&gt;1. The Limitation of Standard Type Annotations (:)
&lt;/h2&gt;&lt;p&gt;Let&amp;rsquo;s review the limitations of standard type annotations.&lt;/p&gt;</description></item><item><title>TypeScript Path Aliases: Clean Imports at Scale</title><link>https://takao.blog/web/typescript-path-aliases/</link><pubDate>Sun, 22 Dec 2024 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-path-aliases/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-path-aliases-en.png" alt="Featured image of post TypeScript Path Aliases: Clean Imports at Scale" /&gt;&lt;p&gt;TypeScript path aliases eliminate the pain of deep relative imports like &lt;code&gt;../../../utils/helpers&lt;/code&gt;, replacing them with clean, intention-revealing paths such as &lt;code&gt;@utils/helpers&lt;/code&gt;. This article covers configuration, bundler integration, testing, and migration strategies.&lt;/p&gt;
&lt;h2 id="configuring-baseurl-and-paths"&gt;Configuring baseUrl and paths
&lt;/h2&gt;&lt;p&gt;The foundation of path aliases is the &lt;code&gt;paths&lt;/code&gt; mapping in &lt;code&gt;tsconfig.json&lt;/code&gt;, combined with &lt;code&gt;baseUrl&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;{
 &amp;#34;compilerOptions&amp;#34;: {
 &amp;#34;baseUrl&amp;#34;: &amp;#34;.&amp;#34;,
 &amp;#34;paths&amp;#34;: {
 &amp;#34;@/*&amp;#34;: [&amp;#34;./src/*&amp;#34;],
 &amp;#34;@components/*&amp;#34;: [&amp;#34;./src/components/*&amp;#34;],
 &amp;#34;@utils/*&amp;#34;: [&amp;#34;./src/utils/*&amp;#34;]
 }
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;baseUrl&lt;/code&gt; sets the base directory for resolving non-relative module names. &lt;code&gt;paths&lt;/code&gt; maps alias prefixes to file system locations relative to &lt;code&gt;baseUrl&lt;/code&gt;. The wildcard &lt;code&gt;*&lt;/code&gt; matches any path segment after the prefix.&lt;/p&gt;</description></item><item><title>TypeScript Branded Types: Preventing Primitive Confusion</title><link>https://takao.blog/web/typescript-branded-types/</link><pubDate>Tue, 15 Oct 2024 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-branded-types/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-branded-types-en.png" alt="Featured image of post TypeScript Branded Types: Preventing Primitive Confusion" /&gt;&lt;p&gt;TypeScript uses structural typing (duck typing): two types with identical shapes are interchangeable. This causes bugs when primitive types back domain concepts — passing a &lt;code&gt;userId&lt;/code&gt; where an &lt;code&gt;orderId&lt;/code&gt; is expected, both typed as &lt;code&gt;string&lt;/code&gt;. Consider a function that sends an email but accidentally receives a database ID instead of an address because both are &lt;code&gt;string&lt;/code&gt;. Branded types solve this by adding a phantom type marker that differentiates structurally identical types at compile time with zero runtime cost.&lt;/p&gt;</description></item><item><title>TypeScript Project References: Scaling Large Codebases</title><link>https://takao.blog/web/typescript-project-references/</link><pubDate>Tue, 13 Aug 2024 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-project-references/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-project-references-en.png" alt="Featured image of post TypeScript Project References: Scaling Large Codebases" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;As TypeScript codebases grow, the monolithic &lt;code&gt;tsconfig.json&lt;/code&gt; approach breaks down. Every invocation of &lt;code&gt;tsc&lt;/code&gt; type-checks and emits the entire project — a process that can take minutes even with &lt;code&gt;--noEmit&lt;/code&gt; in large monorepos. Worse, without module boundaries, any file can import any other file, creating tangled dependency graphs that are difficult to refactor. &lt;strong&gt;TypeScript Project References&lt;/strong&gt; solve this by allowing you to split your codebase into independent sub-projects, each with its own &lt;code&gt;tsconfig.json&lt;/code&gt;, enabling incremental builds, enforced API boundaries, and dramatically faster type-checking.&lt;/p&gt;</description></item><item><title>TypeScript Generic Constraints: Building Type-Safe APIs</title><link>https://takao.blog/web/typescript-generic-constraints/</link><pubDate>Tue, 05 Mar 2024 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-generic-constraints/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-generic-constraints-en.png" alt="Featured image of post TypeScript Generic Constraints: Building Type-Safe APIs" /&gt;&lt;p&gt;TypeScript generics let you write reusable, type-safe code, but without constraints they are too permissive. The &lt;code&gt;extends&lt;/code&gt; keyword restricts type parameters to shapes that have specific properties, giving you both flexibility and safety.&lt;/p&gt;
&lt;h2 id="the-extends-constraint"&gt;The extends Constraint
&lt;/h2&gt;&lt;p&gt;The foundation of generic constraints is the &lt;code&gt;extends&lt;/code&gt; keyword. It ensures a type parameter satisfies a required structure:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;function getProperty&amp;lt;T, K extends keyof T&amp;gt;(obj: T, key: K): T[K] {
 return obj[key];
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here &lt;code&gt;K extends keyof T&lt;/code&gt; guarantees &lt;code&gt;key&lt;/code&gt; is a valid property of &lt;code&gt;obj&lt;/code&gt;. Attempting to pass an invalid key triggers a compile-time error. Common patterns include constraining to interfaces (&lt;code&gt;T extends { id: string }&lt;/code&gt;), union members, or primitive types.&lt;/p&gt;</description></item><item><title>TypeScript Utility Types: Complete Guide with Real Examples</title><link>https://takao.blog/web/typescript-utility-types/</link><pubDate>Sun, 10 Dec 2023 00:00:00 +0900</pubDate><guid>https://takao.blog/web/typescript-utility-types/</guid><description>&lt;img src="https://takao.blog/img/thumbnail/typescript-utility-types-en.png" alt="Featured image of post TypeScript Utility Types: Complete Guide with Real Examples" /&gt;&lt;p&gt;TypeScript provides a rich set of built-in utility types that transform and manipulate other types. Understanding these tools lets you write more expressive and type-safe code without reinventing the wheel.&lt;/p&gt;
&lt;h2 id="property-modification-types"&gt;Property Modification Types
&lt;/h2&gt;&lt;p&gt;These types modify the optionality, mutability, and requirement of object properties:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;interface User {
 id: number;
 name: string;
 email?: string;
}

type PartialUser = Partial&amp;lt;User&amp;gt;;
// { id?: number; name?: string; email?: string; }

type RequiredUser = Required&amp;lt;User&amp;gt;;
// { id: number; name: string; email: string; }

type ImmutableUser = Readonly&amp;lt;User&amp;gt;;
// { readonly id: number; readonly name: string; readonly email?: string; }
&lt;/code&gt;&lt;/pre&gt;&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Type&lt;/th&gt;
					&lt;th&gt;Effect&lt;/th&gt;
					&lt;th&gt;Common Use&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;Partial&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;All properties optional&lt;/td&gt;
					&lt;td&gt;PATCH request bodies&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;Required&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;All properties required&lt;/td&gt;
					&lt;td&gt;Form submission validation&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;Readonly&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;All properties read-only&lt;/td&gt;
					&lt;td&gt;Configuration objects&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;Partial&lt;/code&gt; is especially useful for API update operations where clients should be able to send a subset of fields:&lt;/p&gt;</description></item></channel></rss>