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】オブジェクト型

Posted at

object

// objectでは内容が変更されてもエラーは発生しない
let profile1: object = { name: "田中" }
profile1 = { birthYear: 3000 }

// 以下のように指定することで内容にも型を指定することができる
let profile2: { name: string } = { name: "田中" }
// profile2 = { birthYear: 3000 }
// error TS2322: Type '{ birthYear: number; }' is not assignable to type '{ name: string; }'.
// Object literal may only specify known properties, and 'birthYear' does not exist in type '{   name: string; }'.
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?