LoginSignup
92
35

More than 3 years have passed since last update.

TypeScript: 配列から要素の型を取得する

Last updated at Posted at 2019-05-03

number型の添字を使うと配列から要素の型を取得可能。

const MyArray = [
    { name: "Alice", age: 15 },
    { name: "Bob", age: 23 },
    { name: "Eve", age: 38 }
];

type T = (typeof MyArray)[number];
// => type T = { name: string; age: number; }


92
35
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
92
35