1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【TypeScript】keyofメモ

Last updated at Posted at 2022-01-31

TypeScriptで keyof を利用すると、オブジェクトのプロパティ名を抽出し、ユニオン型を生成できる。
keyof T => T typeのプロパティ名のユニオン型 を表現できる。

type Item = {
  title: string;
  description: string;
};

type ItemKey = keyof Item;
// ItemKey は 'title'|'description' というユニオン型になる
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?