0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TypeScriptでPickを利用する

Posted at

はじめに

TypeScriptで基本型に対し、一部の型を取得するPickを紹介します。

ソースコード

pick.ts
type Person = {
    name: string;
    age: number;
    address: string;
  };

//   type PersonBasicInfo = Pick<Person, 'name' | 'age'>;
  type PersonBasicInfo = Pick<Person, 'name'>;

  const person: PersonBasicInfo = {
    name: 'Alice',
  };
  
  console.log(person); // { name: 'Alice' }

実行結果

実行結果
~/develop/react/typescript_node$ ts-node pick.ts
{ name: 'Alice' }
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?