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?

More than 1 year has passed since last update.

TypeScript「?」について

Last updated at Posted at 2022-12-30

はじめに

TypeScript のオブジェクトにプロパティを任意に設定することができるオプショナルオプション(Optional Property)機能が備わっています。この機能は、プロパティの末尾に「?」を付けることでオブジェクトのプロパティを任意に設定できます。ここで言う「任意に設定」とは、対象のプロパティを値を設定する、設定しないを意味しています。

type Person = {
    name: string,
    age: number,
    address?: string
}

const member: Person = {
    name: "Member User", // 必須
    age: 10              // 必須
    address: 'address'   // 任意
}

環境

項目 バージョン
OS Ubuntu 18.04.5 LTS
Visual Studio Code 1.57.1
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?