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.

【メモ】JS・TSにおける定数オブジェクトの設定について

Posted at

下記の方法で、下記が実現できる

  • オブジェクト自体の再代入が防げる
  • オブジェクトのプロパティとその値が不変になる
export const SAMPLE_OBJECT = Object.freeze({
    NOT_SET: "未設定",
    AAA: "aaa",
} as const)

as const

提供元:TypeScript
作動タイミング:コンパイル時に作動

Object.freeze()

提供元:JavaScript
作動タイミング:ランタイム時に作動

0
0
1

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?