0
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 1 year has passed since last update.

Record<Keys, Type>について

Posted at

プロパティのキーがKeys、プロパティの値がTypeであるオブジェクトの型を作るユーティリティ型

  • Keys
    • オブジェクトのプロパティキーを指定する
    • 代入できる型は、string, number, symbolとそれぞれのリテラル型
  • Type
    • オブジェクトのプロパティの値の型を指定する
    • 任意の型を代入できる
// キーがstringで値がnumberのインデックス型を定義する
type StringNumber = Record<string, number>;
const value: StringNumber = { a: 1, b: 2, c: 3 };

// キーがfirstName,middleName,familyNameで、値が文字列であるオブジェクトの型を定義する
type Person = Record<"firstName" | "middleName" | "lastName", string>;
const person: Person = {
  firstName: "Robert",
  middleName: "Cecil",
  lastName: "Martin",
};

0
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
0
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?