Skip to Content
Effective TypeScript 第2版 ―型システムの力を最大限に引き出す83項目
book

Effective TypeScript 第2版 ―型システムの力を最大限に引き出す83項目

by Dan Vanderkam, 今村 謙士
April 2025
Intermediate to advanced
448 pages
6h 50m
Japanese
O'Reilly Japan, Inc.
Content preview from Effective TypeScript 第2版 ―型システムの力を最大限に引き出す83項目

6章ジェネリックと型レベルプログラミング

TypeScriptの型システムは、JavaScriptのコードの実行時の振る舞いをモデリングするよう設計されています。JavaScriptは非常に動的で寛容なため、TypeScriptの型システムは常により強力な機能を開発する必要に迫られてきました。「項目15 型演算とジェネリック型を使って重複を避ける」で説明したように、型のマッピングのロジックもそのような強力な機能の1つです。

そのような強力な機能とジェネリック型エイリアスを組み合わせると、TypeScriptの型システムはそれ自体が独立したプログラミング言語と考えることができるほど強力になります(TypeScriptの型システムはチューリング完全(https://oreil.ly/snlm0)なので、これは実際間違っていません)。JavaScriptのように値を使ってプログラミングするのではなく、型を使ってプログラミングするのです。つまり、型レベルプログラミングです。これはメタプログラミング(プログラムを操作するプログラムを書くこと)とは異なりますが、この2つの用語はときどき混同されます。

新しい言語を学ぶのは楽しいもので、ゲームからSQLパーサーまで、TypeScriptの型システムを使って作られたさまざまな種類の意欲的なアプリケーションがあります。これはある程度、Type Challenges(https://tsch.js.org)プロジェクトのおかげでもあります。Type Challengesは、だんだん難しくなっていく何百もの型システムのパズルを含みます。この章を読みながらそれらを解いていけば、学んだことをしっかり定着させられるでしょう。

この章は、いくつかの注意点も含みます。TypeScriptに型レベルのプログラミング言語が備わっているとは言え、それは必ずしも直感的で、人間工学的で、扱いやすい言語なわけではありません。型レベルでロジックを書けるからといって、それが常に良いアイデアとは限りません。ジェネリック型を使いすぎると、暗号のようなメンテナンスしにくいコードになりかねません。Josh ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

LLMのプロンプトエンジニアリング ―GitHub Copilotを生んだ開発者が教える生成AIアプリケーション開発

LLMのプロンプトエンジニアリング ―GitHub Copilotを生んだ開発者が教える生成AIアプリケーション開発

John Berryman, Albert Ziegler, 服部 佑樹, 佐藤 直生
JavaScript 第7版

JavaScript 第7版

David Flanagan, 村上 列
入門 Kubernetes

入門 Kubernetes

Kelsey Hightower, Brendan Burns, Joe Beda, 松浦 隼人

Publisher Resources

ISBN: 9784814401093Publisher Website